How to get the push notification payload when force-quit / swipe up to kill the iOS app without tapping on the banner/alert?

亡梦爱人 提交于 2021-01-04 03:12:49

问题


I’m building an app which handles notifications pushed from Parse, and trying to create a notification history function. I’ve enabled the background modes successfully, so when the app is running in the background, the app can get the payload well via application:didReceiveRemoteNotification:fetchCompletionHandler even the banner/alert is not tapped. However, when force-quit / swipe up to kill the app, application:didReceiveRemoteNotification:fetchCompletionHandler is not called.

Is there any method to implement for getting the push notification payload when the app is killed without tapping the banner/alert? Thank you in advance!


回答1:


You can't get a notification's payload if your app is killed.

In most cases, the system does not relaunch apps after they are force quit by the user. One exception is location apps, which in iOS 8 and later are relaunched after being force quit by the user. In other cases, though, the user must launch the app explicitly or reboot the device before the app can be launched automatically into the background by the system. When password protection is enabled on the device, the system does not launch an app in the background before the user first unlocks the device. - Understanding When Your App Gets Launched into the Background

Anyway, push notifications are not reliable.
It means that you can not be sure that they will ever be delivered.

If you want to keep a "notification history" list, do it server-side and fetch it in-app (in a totally not push related way).

Each time you send a push notification, keep it's content in database, like any object. Then when the user opens the history list, fetch the list like any other parse object.



来源:https://stackoverflow.com/questions/30571701/how-to-get-the-push-notification-payload-when-force-quit-swipe-up-to-kill-the

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