INDIA +91 964 309 2571 | USA +1669 327 4700 info@navyuginfo.com

Notifications in iOS are two types:
1) Remote Notifications
2) Local Notifications

Local Notifications are scheduled by an app and delivered on the same device. When you create a local notification, you must specify when the system should deliver the notification. No server-side programming is required and no internet is required to fire local notifications.
E.g.: To-Do Lists, Reminders
Remote Notifications (Push Notifications) are notifications sent by the server. Apple Push Notification service (APNs) is the primary technology for the remote-notification feature. Apple Push Notification service uses a remote design to deliver remote notifications to devices and computers.

Path of a remote notification is shown below:

APNs transports and routes remote notifications from your provider to your app on user devices. When your provider determines a notification should be sent, your provider sends the notification, along with a token to identify the destination device, to APNs. The APNs servers route the notification and the device’s operating system delivers it to your app.

Apple even supports silent push notifications. They can be used to inform the application of new content without having the user informed. Instead of displaying a notification alert, the application will be awakened in background and notification handler will be called. You then have the opportunity to process any information transparently for the user.

Issues faced during Implementation of notifications in the Sample Application:
In this application, remote notifications were needed to be implemented and only one notification should be visible to the user at a time i.e. the new notification should override the previous existing notification. Project’s main motive is to spread knowledge to the user by just engaging the user for one minute, so we don’t want to bug the user with multiple notifications in the user’s device.
The overriding feature of notifications can be done easily in android because each notification in Android has a (tag, id) associated with it and the cancel (int id) method can be used to cancel the notification with a particular id. But iOS doesn’t allow us to manipulate with remote notifications, so we cannot cancel or override a remote notification.

Then we implemented silent push notifications i.e. every time a notification is pushed to the user, we were changing it to local notification and displaying a local notification to the user. Local notifications can be manipulated by the user. There are methods like cancelLocalNotification (_notification:UILocalNotification) and cancelAllLocalNotifications () to cancel local notifications. But there is a catch here, local notifications can be fired only when the app is in foreground or background but not in suspended (user kills the app) and an app cannot be forever maintained in the background state. So it is not possible in iOS to make only a single notification visible to user till iOS 10 update.

What’s new in notifications in iOS 10
In the iOS 10 update, new frameworks for more user interactive notifications have been introduced. They are UserNotifications and UserNotificationsUI and older notification frameworks like UIUserNotificationSettings, UILocalNotification etc have been deprecated in iOS 10. Notification management is new with these frameworks and this allows you to have access to notification that is pending delivery for your locally scheduled notifications. Apps and app extensions can use UserNotifications framework to receive and potentially modify local and remote notifications when they are delivered to the user’s device. Now you can also remove notifications that have already been delivered to the user, as well as update and promote these notifications by using UNUserNotificationCenter and its delegate methods.

The APNs provider API introduced in iOS10 lets you send remote notifications to your app on iOS, tvOS, and macOS devices, and to Apple Watch via iOS. The API is based on the HTTP/2 network protocol. Each interaction starts with a POST request, containing a JSON payload that you send from your provider server to APNs. APNs then forwards the notification to your app on a specific user device. In this API a header apns-collapse-id is introduced which enables multiple notifications with same collapse identifier to display to the user as a single notification i.e. notifications are being overridden.

Following is the example of a POST request to https://api.push.apple.com/3/device/deviceToken
where deviceToken is the deviceToken of the device for which you have to send the notification
headers {“apns-collapse-id” : “1” , “apns-topic” : “appBundleId”} , body { “aps” : { “alert” : “Hello” }}

For more info on APNs please refer to the below link
https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html
To learn more about what’s new in notifications in iOS 10, please visit the below link
https://developer.apple.com/videos/play/wwdc2016/707/

Hope this provides you all solution to Push Notifications problems in iOS.