Silent notification callback method called only when app is in background

回眸只為那壹抹淺笑 提交于 2020-01-16 02:49:05

问题


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.



来源:https://stackoverflow.com/questions/30311771/silent-notification-callback-method-called-only-when-app-is-in-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!