在不同状态下接收推送通知
我知道这个话题已经被讨论过,但是我不断看到相互矛盾的内容,我只是越来越迷失。
我只想知道当我的应用程序在后台并且收到推送通知时会发生什么。
我知道:
在前台时 - application:didReceiveRemoteNotification: 被调用,并且没有警报、徽章或声音。
尚未启动时 - 显示/播放警报、徽章和/或声音,如果用户点击通知的“查看/打开”(操作)按钮,则会启动应用程序并调用 application:didFinishLaunchingWithOptions: 并传递通知有效负载,如果用户关闭通知并点击应用程序图标,会调用相同的方法,但不会传递有关通知的信息。
在后台时 - 这就是我困惑的地方。我需要知道在后台运行或暂停是否会产生影响,以及在任何情况下调用什么方法以及是否显示/播放警报、徽章和/或声音。
谢谢。
I know this topic has been discussed however i keep seeing conflicting stements and im just getting more and more lost.
I just want to know what happens when my app is in the background and it receives a push notification.
I know that:
While in foreground -
application:didReceiveRemoteNotification: is called and there is no alert, badge or sound.
while not launched -
alert, badge and/or sound is shown/played and if the user taps the "View/Open" (Action) button of the notification, the app is launched and application:didFinishLaunchingWithOptions: is called and the notification payload is passed, if the user closes the notification and taps the app icon, the same method is called however no information about the notification is passed.
while in background -
Here is where im confused. I need to know if being in the background running or suspended makes a difference and in whatever case what method(s) are called and if the alert, badge and/or sound is shown/played.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会发现 这个答案到如果应用程序已在后台运行,如何响应推送通知视图有用。
基本上,您可以使用以下代码判断您的应用程序是否刚刚在 application:didReceiveRemoteNotification: 中进入前台:
You might find this answer to How to respond to push notification view if app is already running in the background useful.
Basically, you can tell whether your app was just brought to the foreground or not in application:didReceiveRemoteNotification: using this bit of code: