djacobs / PyAPNs

Python library for interacting with the Apple Push Notification service (APNs)
http://pypi.python.org/pypi/apns/
MIT License
1.22k stars 374 forks source link

'GatewayConnection' object has no attribute '_sent_notifications' #156

Closed satish-gathole-driveu closed 8 years ago

satish-gathole-driveu commented 8 years ago

I am using TestFlight to build new release. To send the notification following code I am using

import time
from apns import APNs, Frame, Payload
from django.conf import settings

apns = APNs(use_sandbox=True, cert_file=settings.BASE_DIR+'/cert.pem', key_file=settings.BASE_DIR+'/key.pem')

token_hex = '3fd05c0acc3ff868d2bed07a16c2c20f636a118ad728fd71831d572f5adf9f8d'
payload = Payload(alert="Hello World!", sound="default", badge=1)
apns.gateway_server.send_notification(token_hex, payload)

frame = Frame()
identifier = 1
expiry = time.time()+3600
priority = 10
frame.add_item(token_hex, payload, identifier, expiry, priority)
apns.gateway_server.send_notification_multiple(frame)

but I am getting following error...

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-f08c632ccb4e> in <module>()
----> 1 apns.gateway_server.send_notification_multiple(frame)

/Users/gathole/.virtualenvs/driveu/lib/python2.7/site-packages/apns.pyc in send_notification_multiple(self, frame)
    557 
    558     def send_notification_multiple(self, frame):
--> 559         self._sent_notifications += frame.get_notifications(self)
    560         return self.write(frame.get_frame())
    561 

AttributeError: 'GatewayConnection' object has no attribute '_sent_notifications'
sennoy commented 8 years ago

You should use enhanced=True during APNs creation and this will work. Unfortunately, sending frames with without enhanced is not working for now. Another way is monkeypatching and setting this attribute for 0. But I'm not sure about side-effects in this case.

satish-gathole-driveu commented 8 years ago

No error anymore..... but still notifications are not working. Is it because of TestFlight certificate and it is expecting something else??

sennoy commented 8 years ago

You are using sandbox=True - this is counting as development mode. If you want to work it properly on test flight, I think you should set this value to False. Also, pay attention on certs you are using and token_hex. If token_hex is development - you have to use sandbox=True and dev certs. If you are using production tokens - you have to use production certs and sandbox=False. It's better to ask iphone guys if those tokens are development or production.

satish-gathole-driveu commented 8 years ago

Thanks for clarification... It's working now :)

sennoy commented 8 years ago

You are welcome :)