0

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 ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rafael
  • 117
  • 1
  • 9
  • 1
    A 'standard' remote notification can be displayed whether the app is open or not. This is all handled by the operating system, same with local scheduled notifications. iOS knows how to handle them because all of the information that is needed is there for it to display. – Scriptable Nov 21 '19 at 15:19
  • @Scriptable good, now I get it. What if I have to send a request to an endpoint when the notification arrives? I mean I have already implemented, I get the silent notification and with the payload I receive translate it into local notification. Is there a way I can do it with normal notification?, because as you said an standard remote notification can be displayed when app is not open, but considering that I have to send this information to the endpoint, I could not do it when app is completely closed because I need execution time but the notification will be desplayed, am I right about this? – Rafael Nov 21 '19 at 18:02
  • when a standard remote notification is received AND the app is open the app will be notified of it, if the app is killed it will not. but if the user taps the notification the app will start and the launchOptions will contain the APNS data from the notification – Scriptable Nov 22 '19 at 08:18

1 Answers1

1

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

Simon McLoughlin
  • 8,293
  • 5
  • 32
  • 56
  • Even if I am downloading an image to add it in a notification the app does not need to be open in order to do that ?, if not required, what handles image downloading ? IOS? – Rafael Nov 21 '19 at 17:50
  • 1
    @Rafael I haven't tested it, the documentation seems to suggest it is possible. As I said in my answer and listed in the tutorial, you have to create a separate component in your app called a "Notification Service Extension". This probably works similarly to watchkit extensions, where its installed on the Phone when you download the app, but then its registered with the system and the code runs somewhere else – Simon McLoughlin Nov 21 '19 at 19:56
  • I apreciate it, as far as I test it, I will come back to mark it as the answer. – Rafael Nov 21 '19 at 20:06