Notification cannot be received on IOS for the first time with apnsclient for python

StackOverflow https://stackoverflow.com/questions/23658499

  •  22-07-2023
  •  | 
  •  

Вопрос

I use apns-client package in python to push notification to IOS devices

self.con = self.session.get_connection("push_production", cert_file=PRO_PEM_FILE, passphrase=PASS_PHRASE)
self.srv = APNs(self.con)

message = Message([token], badge = badge, alert = alert)
res = self.srv.send(message)

for token, reason in res.failed.items():
   code, errmsg = reason
   print "Device failed: {0}, reason: {1}".format(token, errmsg)

for code, errmsg in res.errors:
   print "Error:", errmsg

if res.needs_retry():
   retry_message = res.retry()

With the code above,I can receive notification most of the time. However,if several hours has passed since the last notification is received,I can not receive notification without any exception at server side. I can tell the code self.srv.send(message) did excute without any response,according to the apns-client document,no response means sending notification successfully.

What can I do to make sure client does receive server's notification? Any help will be appreciated!

Это было полезно?

Решение

Push Notification is not 100% reliable and it will not guaranteed that you will receive it 100% of the time.

See: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

Quality of Service

Apple Push Notification service includes a default Quality of Service (QoS) component that performs a store-and-forward function.

If APNs attempts to deliver a notification but the device is offline, the notification is stored for a limited period of time, and delivered to the device when it becomes available.

Only one recent notification for a particular application is stored. If multiple notifications are sent while the device is offline, each new notification causes the prior notification to be discarded. This behavior of keeping only the newest notification is referred to as coalescing notifications.

If the device remains offline for a long time, any notifications that were being stored for it are discarded.

If you have any important message that you want the user to receive, I would like to suggest you to try Local Notification.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top