Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Handling Silent Push Notifications When App Is Force-Quit By User

I am currently facing a problem with push notifications in iOS.

My app receives silent push notifications containing an identifier. This identifier is then used to fetch data from a remote server from which a local notification is created.

As far as I'm aware, if the user has force-quit an app (i.e. by double tapping the home button and swipe closing the app) then the silent push notification does not get passed onto the didReceiveRemoteNotification method in the AppDelegate class [1] [2], thus preventing the app from doing any kind of processing.

I have done a fair amount of research into handling the situation mentioned above. However, was unable to find a definitive answer and was hoping someone could help me out or point me in the right direction.

TLDR: What should I do when the user has force-quit my app, but I still need to process a silent notification?

Further Information:
My app only needs to support iOS8+.

[1] https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1

The Notification Payload
If the target app isn’t running when the notification arrives, the alert message, sound, or badge value is played or shown. If the app is running, the system delivers the notification to the app delegate as an NSDictionary object.

[2] https://stackoverflow.com/a/19202487/2472819

like image 544
user2472819 Avatar asked Apr 27 '15 22:04

user2472819


People also ask

Do push notifications work when app is closed iOS?

Apple does not offer a way to handle a notification that arrives when your app is closed (i.e. when the user has fully quit the application or the OS had decided to kill it while it is in the background). If this happens, the only way to handle the notification is to wait until it is opened by the user.

Will iOS awake my app when I receive silent push notification?

According to Apple's official documentation, “A silent push notification is a notification that doesn't display an alert, play a sound, or badge your app's icon. It wakes your app in the background and gives it time to perform some actions”.

How do you silence app notifications on iPhone?

Go to Settings > Focus. Tap Do Not Disturb. You can select allowed or silenced notifications from people and apps, connect your Lock Screen or Home Screen, have this Focus turn on automatically, and add Focus filters.

How do I make push notifications silent?

There are two ways users can receive silent push notifications on Android. Users can long press on a notification to get an option to display notifications silently. Users can also enable silent notifications by heading to Settings > App & Notifications > Search for app and choose> Notifications, and turn it off.


1 Answers

Previously in iOS 7 and before, once a user force-quit an app, it will not be able to run and background tasks at all, including location monitoring, push notification handling with content-available:1 etc.

However the problem is that such behavior is not documented. The reason is that it may change in a new iOS update and Apple doesn't want to nail the coffin too early. As in iOS 8, PushKit is introduced and is supposed to be able to deal with the force-quit scenario. Please check this tutorial for details: https://zeropush.com/guide/guide-to-pushkit-and-voip

like image 96
superarts.org Avatar answered Sep 23 '22 22:09

superarts.org