How are push notifications delivered through APNS when app is completely closed?

247 views Asked by At

I am developing a framework that process silent notifications in order to deploy a local notification (with an alert), the reason of this is that I am sending data messages from Firebase where the payload has custom key-value pairs (that indicates how the notification must behave), so I have to receive them in the app in order to translate them.

Everything works fine, I am receiving notifications in foreground and background while the app is executing. The problem is that I can not receive notifications when the app is killed by the user or completely closed. The reason of this is indicated in Apple docs that says that didReceiveRemoteNotification:fetchCompletionHandler will not be executed if the user has closed the app because the system will not launch the app.

So, I was told that I should be using default apns key-value pair to receive a default push notification even when the app is closed and use Notification Service Extension if I want to modify or add something to the notification getting the request´s content.

The problem I have is that I should do some extra process when I receive a silent notification, like reporting that I receive it. And this is the reason I think the app should be executing, because it need execution time.

But I been thinking and researching and I cannot understand how other apps (like youtube, facebook .. etc) can receive notifications with an image attach even if the app is closed, is it not supposed that in order to add an attachment you need to have whatever you are attaching locally ?, so you should have downloaded it somehow, and this process require the app to have time for executing that task, or this is managed by IOS ?

Or am I missing something about push notification ?

1

There are 1 answers

3
Simon McLoughlin On

iOS 10 brought in the concept of "rich notifications". Yes it is ultimately delivered through a regular push notification. But it contains links to the image (or other media / data).

Creating a "Notification Service Extension" inside your app allows you to run code for when the notification is delivered, such as downloading an image passed by a "media-url" in the payload.

You can also create a "Notification Content" target to allow you to customise the UI, allowing you to expand the notification to show a UIViewController to show additional data / content.

Here is a link to a tutorial to get you started: https://medium.com/@tsif/ios-10-rich-push-notifications-with-media-attachments-a54dc86586c2