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

send_notification_multiple stopped working suddenly #181

Open contacitltd opened 7 years ago

contacitltd commented 7 years ago

I have been using the send_notification_multiple function for quite some time, but it has stopped working yesterday.. When I add more than one notification to the frame, the messagses are not delivered to the devices (when there is only one notification in the frame, it does work). As I used this for a long time before it recently stopped working, i can only suspect Apple has changed something in the API?

For reference, here is my code:

identifier = 3
expiry = time.time()+(3600*24*7)
priority = 10
payload = Payload(alert="test message", sound="default", badge=1, custom={"update":"news"})
frame = Frame()
for reg_id in reg_ids:
   frame.add_item(reg_id, payload, identifier, expiry, priority)
self.apns.gateway_server.send_notification_multiple(frame)

Has anyone experienced a similar issue?

sanderfoobar commented 7 years ago

Does not work for me too. I can give more info if required, for now @contacitltd example should be enough.

In the mean time, I take it Apple will not like it if you send 30k push notifications with the send_notification() method?

djeer commented 7 years ago

I seem to have the same problem. Here's my code:

...
frame_cl = Frame()
...
for *something*
    frame_cl.add_item(token, payload, identifier, expiry, priority)
...
apns_cl = APNs(use_sandbox=False, cert_file='*dir*/****.pem')
apns_cl.gateway_server.send_notification_multiple(frame_cl)     
...

I have this error:

  File "/*myproject*/send.py", line 218, in send_notice
    apns_cl.gateway_server.send_notification_multiple(frame_cl)
  File "build/bdist.linux-x86_64/egg/apns.py", line 559, in send_notification_multiple
    self._sent_notifications += frame.get_notifications(self)
AttributeError: 'GatewayConnection' object has no attribute '_sent_notifications'
djeer commented 7 years ago

It's fixed in this fork https://github.com/mnemonicflow/PyAPNs here https://github.com/mnemonicflow/PyAPNs/commit/f07515ec610475a715f6fd3e35595f875b13586d This projest seems to be abadoned

connectarena commented 7 years ago

same issue here.. and above fork by @diman94 is not reachable (broken link). any one knows the actual link?

djeer commented 7 years ago

I almost shure I have it on my computer. I will upload it tomorrow if I don't forget. You may look through recent forks of this project (as I did), maybe you'll find something useful.

djeer commented 7 years ago

Try this one https://github.com/diman94/PyAPNs/ As I remember self._sent_notifications += frame.get_notifications(self) replaced with if self.enhanced: self._sent_notifications += frame.get_notifications(self)

markleetw commented 7 years ago

@contacitltd @skftn @connectarena Excuse me. Would you mind to tell me if you're using enhanced mode or not?

I'm using very old version of PyAPNs and legacy notification (not enhanced notification), but recently I often got stuck when sending multiple notifications. It really bothers me, so I'm trying to upgrade the lib and replace with the enhanced mode. Till now, I haven't met the same issue in sandbox testing yet, but according to my experience, it's not easy to reproduce, so I need more details about your questions to infer if the stuck problem still remains, if so, maybe I should think a plan B.

MrCsabaToth commented 7 years ago

I thought it worked at some point in the past, but my problem is only involving banner type notifications when the application is not in the foreground.

monstermac77 commented 4 years ago

Given what @djeer said about what fix was made in that fork, and that self._sent_notifications = collections.deque(maxlen=SENT_BUFFER_QTY) has now been moved out of the if enhanced block of the init for APNs in the source repo, I think this was a bug that probably doesn't exist anymore and this issue should be closed.