I have an application which receives Push Notification and these notifications are delivered properly to the device. However when these notifications are delivered badge does not count. I have read online that one sends badge number with the payload which I understand but does not work for my case. Notifications are delivered based on different instances and I want to be a able to increase the badge number based on the available notifications the user has not opened his device to view.
With payload, there is no way to know if a user viewed the notification already and zero it. I am trying to avoid setting a badge in the payload to maybe 7 whereas the unopened notification on the device is one.
Since push notification are handled by iOS and not by ios app you can't change the application badge on receiving a push notification.
Though you can send the badge number in the payload of the push notification as you already send, so you have to do the calculation on server side.
Go through Local and Push Notification Programming Guide and especially the The Notification Payload.
Related
Apps in IOS generally show a badge counter telling how many unread notifications are pending for that app. My understanding is that, to update the badge counter, increment or decrement, we need to send a push notification with the current counter value.
I was testing the behaviour of Gmail app, and even if I mark a message as read on my laptop's browser, the counter on App on IOS got decremented to represent the correct value, without receiving any push notification. I had killed the app on IOS before testing it.
I am wondering how Gmail does that. Can silent push notifications, let us update the app badge counter without showing notification alert? Do silent push notifications work at all, when the app is in killed state?
You can update your app's badge count by sending the new count from the server. For example by sending:
{
“aps” : {
“badge” : 9
}
}
As the payload you would set the badge to 9.
For more on the APNS payload, you can check the docs
On iOS it doesn't matter if the app is killed or not to receive a push notification (btw, that's why they are push notifications). In order to update the badge number, you can send the Background Notification (silent notification), which wakes your app so that your app can update, fetch new content.
Read the Docs
Apple doc says that if there are multiple notifications to be delivered then only the last notification will be delivered to the phone because the Queue size is 1. So If my app goes offline and there are like 40 notifications to be delivered, when my app comes online I only get one notification instead of all 40.
I have tested this with WhatsApp and it gets all the notifications even though the app is killed.
How can I ensure I receive all the notifications as well?
Here's what docs state:
The priority of the notification. Specify one of the following values:
10–Send the push message immediately. Notifications with this priority
must trigger an alert, sound, or badge on the target device. It is an
error to use this priority for a push notification that contains only
the content-available key.
5—Send the push message at a time that takes into account power
considerations for the device. Notifications with this priority might
be grouped and delivered in bursts. They are throttled, and in some
cases are not delivered.
And about VoIP:
Instead of persistent connections, developers should use the PushKit
framework—APIs that allows an app to receive pushes (notifications
when data is available) from a remote server. Whenever a push is
received, the app is called to action. For example, a VoIP app could
display an alert when a call is received, and provide an option to
accept or reject the call. It could even begin taking precursory steps
to initiate the call, in the event the user decides to accept.
Do I understand correctly that apns-priority defines message queuing at APNS side, and VoIP push type defines what happens on the device?
And what do they mean saying
It is an error to use this priority for a push notification that contains only the content-available key.
Will APNS return an error or is it just a bad practice?
P.S. I use AWS SNS for sending notifications and it does not support customisation of apns-priority, but I am curious how it affects the process.
The main difference is that even if your app is closed voip notification can wake your app for kill/suspended state and user notification just shows an alert without waking up your app for more refer.
Apple documentation for pushkit
The main difference is that VoIP notification will launch your app if it's not running or was killed from app switcher and you need to handle the notification in your code, while the normal notification will be shown immediately as local notification and will not start your app.
My app will run in the background for ~10 minutes before the system shuts it down. During this time, if the user receives an event, I handle it using Local Notification to inform the user and display a badge icon. Once the App is no longer running in the background a push notification is sent, but when a push is sent, it overrides the current badge count from the local notification since a payload count is attached with the push.
Is there a way to deal with this?
Looks like the OS is responsible appending badge numbers from push payload. It simply places whatever count the payload has associated with it.
I'm trying to understand on how to deal with a particular use case with push notifications.
Let's suppose that I have 4 push notifications in the notification center waiting for an interaction, the server keeps track of the badge number. The user picks up one, in the -application:didReceiveRemoteNotification: I decrement the badge and communicate to the server the notification back to make it decrements its "badge" number and mark the notification as read.Everything works fine.
I'm not able to deal with that case. Let's say that the user deletes from the notification center one notification and then opens the app by tapping on another, I will have an incorrect badge number on both server and app, since deleting a notification it doesn't seem to affect the badge number.
Is there a way to understand which remote notification has been removed?
It seem that for a more fine grained control is better to use a mix of silent push and remote notification.