Handle remote notifications when app is killed

Hello fellow developers,


I have a question about handling remote notifications when an app is killed (i.e. manually removed from recent apps).


Let me give you some background information first.

We have a server that sends remote notifications to iOS devices by using APNS. We process the notification in the app and store it on the device itself.

When the app is in the foreground, DidReceiveRemoteNotification() is called, and we can process the notification. We then display an alert dialog.

When the app is in the background (not killed), DidReceiveRemoteNotification() is also called, and we can process the notification. The notification is automatically displayed as a banner.

When the app is killed, DidReceiveRemoteNotification() is not called, so we can not process the notification. However, the notification will be shown as a banner.


We tried to solve this by sending a silent notification first, and then the 'real' notification, but this didn't work out.


Is there any way to process a remote notification in DidReceiveRemoteNotification() when the app is killed? Or is the solution to store all notifications on our server and let the device fetch those when launching?

We have enabled the following background modes: Background fetch and RemoteNotifications.

Thanks,


Martijn

Replies

There is no way to receive remote notification handlers for silent notifications if the app has been force-quit.


See the discussion section of the documentation: https://developer.apple.com/reference/uikit/uiapplicationdelegate/1623013-application

"However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again."


Hope this helps,

DT