didReceiveRemoteNotification not called, When app is killed

1.8k views Asked by At

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"
    }
}
2

There are 2 answers

1
The Dreams Wind On

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.

0
Deepak Pal On

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"
    }
}