4

I have an app implemented with fcm . I can receive push notifications in all cases, that works good. But didReceiveRemoteNotification is not call if app is terminated / kill by user. if app is in background or for-ground it is calling. App is terminated notification is coming, but didReceiveRemoteNotification:fetchCompletionHandler didn't call.

My Question is what is the trigger method app is terminated and a firebase notification received.I used Swift 4.2 and Xcode 10.0. I enable background Modes - Remote notifications from capabilities.

With Firebase I send this JSON:

{ 
 "to": "/topics/group1", 
 "priority" : "high",
 "content-available": true,
 "notification" : {
 "body" : "Yes you recevied !",
 "sound": "default",
 "title" : "Notification"
 },
 "data": {
"type" : "IOS"
    }
}
Sateesh Yemireddi
  • 4,289
  • 1
  • 20
  • 37
Gamsh
  • 545
  • 4
  • 21
  • have you enable background fetch and remote notification? – Pushp Nov 05 '18 at 12:12
  • @Pushp yes enabled – Gamsh Nov 05 '18 at 12:13
  • This is expected behaviour. Your app cannot receive push notifications when it has been terminated by the user. If your app is a voip app then you can use pushkit which will relaunch your app when a push is sent. – Paulw11 Nov 05 '18 at 12:15
  • 2
    When app is killed and notification is received, `didReceiveRemoteNotification:fetchCompletionHandler` is never called. Instead when user taps on notification, data is received in `didFinishLaunchingWithOptions`. – NightFury Nov 05 '18 at 12:31
  • @NightFury Is that none of the method tigers, if notification receive when app is terminated. – Gamsh Nov 06 '18 at 03:34
  • Nopes. But I think extension methods for notification might get call in case app is killed – NightFury Nov 06 '18 at 12:36
  • 1
    @Gamsh did you able to resolve this? I'm having similar problem... The app can't receive the remote notification when the app is removed from the "multitask" list. – SquareBox Nov 22 '18 at 02:03
  • How is the case for silent push notification @Paulw11? App is expected to process a task when we got the silent push notification. – Anthonius Dec 14 '20 at 15:34
  • If the app is terminated then it will not receive silent push notifications. Notifications are not a guaranteed delivery service. – Paulw11 Dec 14 '20 at 19:47

2 Answers2

3

From the Apple docs:

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.

You actually can get it round by enabling VoIP background mode, but it will reduce your chances to pass review in the app store.

Community
  • 1
  • 1
The Dreams Wind
  • 8,416
  • 2
  • 19
  • 49
  • 1
    I would like to update badge number locally. Badge number not come with notification. Is that any way to update when app is terminated state. – Gamsh Nov 06 '18 at 03:36
0

Your key/value for content-available is incorrect. The key is content_available (underscore, not dash) and the value is a boolean, not string:

{ 
 "to": "/topics/group1", 
 "priority" : "high",
 "content_available": true,  // <= CHANGED
 "notification" : {
 "body" : "Yes you recevied !",
 "sound": "default",
 "title" : "Notification"
 },
 "data": {
 "type" : "IOS"
    }
}
Deepak Pal
  • 33
  • 5