0

Right now I have a framework that receives a silent notification, get the data from it (custom data) and translate it into a local notification to show the alert to the user (this is donde in didReceiveRemoteNotification:fetchCompletionHandler method). I have implemented this framework on an app and everything seems to be working correctly, silent notifications are being process when the app is in background and foreground. However, when the app is killed by the user or it is not running, I cannot receive notifications because of this:

Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives. 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.

The reason I use this method for showing notifications is because the payload I sent to APNS has custom data with key-values that indicate how the notification must behave.

I've been doing some research and I found that Pushkit for VoIP can do the job. However, many post suggest that this can cause app rejection.

So my question is, how can I achieve receiving remote notifications even if my app was killed and considering that data in the payload has custom information to build the notification?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rafael
  • 117
  • 1
  • 9
  • 2
    In the past you could use PushKit but now you can only do so to indicate an incoming call for a voip app. If you receive a PushKit notification and do not subsequently indicate an incoming call to iOS your app will be terminated. There is no solution for your problem. If the user terminated the app you will not receive remote notifications until the user re-launches the app. Consider adding a default notification payload to be shown if your app isn't running. – Paulw11 Nov 19 '19 at 19:33
  • I really appretiate it @Paulw11, I just was like looking a confirmation since I been researching a lot. I just have a doubt. When sending default push notification, with apns predefined keys, a notification as an alert can be displayed even if the app is not running, this behavior is because the notification is processed for IOS tray, and what I am doing with silent notification is processed inside the app, that is why the app must be running. am I right about this ? – Rafael Nov 19 '19 at 20:27
  • 1
    Yes, that could be an issue; I am not sure if iOS will suppress the alert part of the message if your app is running. You might need to test that – Paulw11 Nov 19 '19 at 20:30

1 Answers1

2

Silent push notifications are unreliable: they might get delayed, delivered in groups or even not delivered at all.

If you need to modify the content of the notification before presenting a banner for the user, you should use a Notification Service App Extension. You can also share some information between your app and this extension - using app groups or the keychain - if it needs something from your app to process the notification data.

pepsy
  • 1,437
  • 12
  • 13
  • Is it possible to get the whole payload of the request I mean, I use other key-value than predefined apns, so can I get the whole payload in order to add some behavior to the notification. – Rafael Nov 20 '19 at 01:38
  • I read about Notification Service App Extension and the problem is that if the app is completely closed I will not be able to modify the request. but what I don´t know is if the app is completely closed the request will be set in the notification center ? – Rafael Nov 20 '19 at 02:13
  • I’m not sure about it, but I guess you should be able to access the whole payload. What do you mean by completely closed? I’ve still never used this extension, but I’ll have to in the next few weeks. If I find new answers when implementing it, I’ll come here to share them. – pepsy Nov 20 '19 at 08:57
  • This is still the case in 2023 for iOS... Your background push won't actually be received when the apns-priority is set to 5. You're not allowed to set it to 10 (deliver immediately). There are unfortunately for iOS users many use cases when you'd want the background to be immediate, including life saving devices over BLE. It's frustrating Apple has implemented pushes so siloed compared to Android... – Kevin Parker Jul 23 '23 at 16:55