Apple Push Notification not received sometimes (JavaPNS) - ios

I'm making a chat with a notification service. Sometimes that the notifications dont arrives to my device. I'm using JavaPNS, so my code isn't very complex, but when I send a lot of messages very quickly (about 10) from one device to another, I don't receive all the notifications. Some of them are lost in the way (generally one of two).
Here is my code:
PushNotificationPayload payload = PushNotificationPayload.complex();
payload.addAlert("Name : text"); payload.addSound("default");
payload.addBadge(1);
payload.addCustomDictionary("type", NOTIF_MESSAGE);
Push.payload(payload, "******.p12", "password", false, URI);

It's OK.
Important: Because delivery is not guaranteed, you should not depend
on the remote-notifications facility for delivering critical data to
an application via the payload. And never include sensitive data in
the payload. You should use it only to notify the user that new data
is available.
-Local and Push Notification Programming Guide.

Apple doesn't guarantee that ALL MESSAGES are ever delivered. The documentation says:
delivery of notifications is “best effort” and is not guaranteed.

Related

Apple Push Notification reliablity

The topic I want to discuss may be a duplicate of this question. But still I've a few queries regarding Apple Push Notifications.
I have one app supported on both Android and iOS. The app needs a background service which hits a remote server every minute. The job is simple for Android app but since background tasking is not supported in iOS I need to employ push notifications for iOS app. I am using PushSharp library to deliver push notifications. Apple says that the delivery of push notification is not acknowledged. I cannot afford push notification failure since I need to send a very crucial message through notification. My questions are:
1) What is the failure rate of push notifications?
2) Are push notifications always reliable to send important messages?
3) Assume that the server which is supposed to send push notifications sends a large number of push notifications every minute. What are the chances of push notification failure in such a case?
4) Which circumstances cause push notification delivery to fail?
If you have any useful resources please provide the same. Thanks.
Please find my comments below.Hope this helps.
What is the failure rate of push notifications?
Apple has not disclosed it so far.
Are push notifications always reliable to send important messages?
Delivery of notifications is a “best effort”, not guaranteed. It is not intended to deliver data to your app, only to notify the user that there is new data available.
Please refer - https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
Assume that the server which is supposed to send push notifications sends a large number of push notifications every minute. What are the chances of push notification failure in such a case?
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.
Please refer - https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
Which circumstances cause push notification delivery to fail?
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.
Please refer - https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

iOS Push notification - not guaranteed

I have made a PushChatStarter app for Push Notification from this tutorial
http://www.raywenderlich.com/32963/apple-push-notification-services-in-ios-6-tutorial-part-2
But I find that only some of the messages are being successfully sent. It is mentioned in the tutorial that the push notifications are not guaranteed. I would like to know the reason why this is happening.
I could not understand the solution mentioned in that tutorial. Could anyone explain how to obtain the solution. I would like to know how to make the application reliable.
I found the answer here: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/WhatAreRemoteNotif.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 QoS stores the notification. It retains only one notification per application
on a device: the last notification received from a provider for that application.
When the offline device later reconnects, the QoS forwards the stored notification to the device.
The QoS retains a notification for a limited period before deleting it.

Sending 10000+ push notifications but not all devices receive it

For our iOS news apps we send out more than 10000 push notifications to registered devices, but somehow not all devices seem to receive the notification. We have been doing this for years but recently we received user feedback stating they did not receive a push notification while they did register their device to receive them.
Our logs show that these specific devices registered successfully and that there were no errors sending the push notification, but somehow the APNS does not deliver the notification. We have seen that removing the app from the device and reinstalling it sometimes solves the problem but we are still concerned.
We think it must be Apple's service that fails to deliver the push notification sometimes, especially when it comes to sending large amounts of notifications. Any of you experienced this?
The Apple docs says this:
Important: Delivery of notifications is a “best effort”, not
guaranteed.
Have you checked the payload size? As per Apple's documentation, the maximum size allowed for a notification payload is 256 bytes.

Apple Push Notification Collapse Key Equivalent

When using Google push notifications, I am allowed to specify a collapse_key value so a device will not receive multiple notifications of the same collapse_key.
Does APNS have a similar feature or does anyone know a way to emulate this functionality?
As of iOS 10 and using the HTTP/2.0 APNS API, you can specify apns-collapse-id header and handle the collapse logic in your app.
Collapsed notifications will appear as one single notification on the device that keeps updating with new data. Each time a notification is updated it is pushed to the top of your unread notifications.
Description of apns-collapse-id taken from https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html:
Multiple notifications with same collapse identifier are displayed to
the user as a single notification. The value should not exceed 64
bytes. For more information, see Quality of Service,
Store-and-Forward, and Coalesced Notifications.
and from https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW1:
When a device is online, all the notifications you send are delivered
and available to the user. However, you can avoid showing duplicate
notifications by employing a collapse identifier across multiple,
identical notifications. The APNs request header key for the collapse
identifier is apns-collapse-id and is defined in Table 6-2.
For example, a news service that sends the same headline twice in a
row could employ the same collapse identifier for both push
notification requests. APNs would then take care of coalescing these
requests into a single notification for delivery to a device.
With iOS 10 there is a new "apns-collapse-id" which looks like it will handle this sort of need. If you have an Apple developer account you can look at the WWDC 2016 notification session videos (707 intro video https://developer.apple.com/videos/play/wwdc2016/707/).
Doody P's answer works for remote notifications, but there is also an equivalent for locally triggered notifications: when you create your UNNotificationRequest, you can set the identifier parameter to whatever you had been using as a collapse key. After being triggered, the push notification will show only the latest version that you sent with that identifier.
(We send push notifications silently through APNs and then retrigger as local notifications, because we need to make sure that our users are logged in.)
There are handy code examples & demos of managing delivered notifications in this WWDC talk - the key section is from ~18:00 - 21:00.
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 app 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.
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
So there's no need for collapse_key in iOS.
FYI, collapse_key is only useful when the device is offline/inactive:
This parameter identifies a group of messages (e.g., with
collapse_key: "Updates Available") that can be collapsed, so that only
the last message gets sent when delivery can be resumed. This is
intended to avoid sending too many of the same messages when the
device comes back online or becomes active (see delay_while_idle).
https://developers.google.com/cloud-messaging/server-ref#downstream
UPDATE:
For both iOS and Android (using collapse_key), if the device is offline (ie the Apple/Google push server cannot reach it), the push server overwrites any previous notification, and only keeps the last one.
If the device is online, then I guess it's up to you to do whatever you want with the received notification. At least in Android you can decide whether you want to "pile things up", whether you want to overwrite any previous notification in the notification area, or whether you want to overwrite any previous notification of the same type.
NotificationManager notificationManager = ...;
String appName = ...;
NotificationCompat.Builder builder = ...
// Always use the same id, so only the last notification will be displayed in the notification area.
int notId = 0;
// Always use a different id, so all notifications will pile up in the notification area
notId = new Random().nextInt(100000);
// Uses the type of notification as id, so you'll only have up to one notification per type
// in the notification area. It's like using collapse_key, but on the app itself.
// That type should should be some additional data in the notification you sent.
notId = notificationType;
Notification notification = builder.build();
notificationManager.notify(appName, notId, notification);
There is no such feature in iOS. However, since push notifications are sent by a server that is in your control, you can keep track of which notifications you've sent to a particular device, and decide whether or not to send new ones. In other words, you put the logic in your server code, not your iOS app code.

Stopping Push Notifications sent to Apple for delivery

Again same question title but requirement is somewhat different.
We have implemented push notification in our application. For some reason there is some problem and lots of push notifications sent to all the participant of our application.
Is there any way to delete notifications sent to apple for delivery ? i.e. messages already send to apple server for delivery of notification.
Sounds weird but need help if possible.
No. As soon as the message is transmitted to Apple, you lose control of it. There are no APIs to cancel a delivery.
For the record: I've built a system we use internally that works as a proxy to Apple's servers. If a message is queued there, we can cancel delivery. But this is completely custom, and the message hasn't actually been delivered to Apple yet.

Resources