0
votes

I want to show show notification based on some condition when receive silent notification then generate local notification. also enable background mode in xcode and enable remote-notification and background fetch. For silent notification message format like this-

{
 "message":{
   "token":"iosdevicetoken",
   "apns": {   
   "payload": {
            "aps": {
                "content-available": 1,
                "category": "GENERAL",
                "priority": "high",
                "token": "randomkey",
                "customkey": "abcs"
            }
        }
    }
  }
}

but below delegate method does not called when app in killed state(swipe from background state)

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
}
1
Push notification not work in killed state. - guru

1 Answers

0
votes

This is intentional. From the documentation for application(_:didReceiveRemoteNotification:fetchCompletionHandler:):

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.

(emphasis added)

iOS sees the user removing the app from the task-switcher as a signal that they don't want the app to run in the background any more. For that reason, iOS won't re-launch the app in the background until the user explicitly relaunches it.