Silent notification callback method called only wh

2019-08-03 06:48发布

问题:

I registered remote notification and its working absolutely fine. Now I am implementing silent notification. For that, I enabled background remote notification and App downloads content from the network.

and sending,

{"aps": {"content-available": 1}}

its calling the below callback method but only when app is in background:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler

And in this method, I am firing local notification after downloading some data from the server. But this method doesn't call at all when app is not in background.

In Apple docs on Push Notification, they are saying:

"When a silent notification arrives, iOS wakes up your app in the background so that you can get new data from your server or do background information processing."

Ideally, silent remote notification should wake up my app in background and the local notification should work.

Any thoughts?

回答1:

After lot of apple docs reading, I found that the method (didReceiveRemoteNotification: fetchCompletionHandler) will not invoke if user has force-quit the app.

As written, (link) 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.