应用程序在后台运行时获取推送通知的自定义负载
嘿,有人能告诉我当应用程序处于后台时如何获取推送通知的自定义负载吗?
如果您的应用程序位于后台,并且您收到推送通知,并且用户点击应用程序“查看”,则应用程序将启动,并且将调用 application:didFinishLaunchingWithOptions:
。在这种情况下,我们可以通过 userInfo
字典中的 UIApplicationLaunchOptionsRemoteNotificationKey
访问自定义通知负载。
如果您的应用程序位于后台并且您收到推送通知并且用户点击应用程序图标,则会将该应用程序带到前台。
发生这种情况时,只会调用 applicationDidEnterForeground:
,并且无法访问推送通知的有效负载。
我的要求是仅注册徽章,没有警报,因此当用户在后台收到通知时没有“查看”按钮来启动应用程序。当用户收到通知并且应用程序处于后台时,用户点击应用程序图标 applicationDidEnterForeground:
被调用。因此,我们无法访问 launchOptions
字典或 userInfo
字典,从中获取通知负载。
我在这里错过了什么吗?
Hey can anybody tell how to get custom payload of push notification when app is in background?
If your app is in the background and you receive a push notification and the user taps app "View", the application is launched and application:didFinishLaunchingWithOptions:
would get called. In this case we can access custom notification payload via UIApplicationLaunchOptionsRemoteNotificationKey
from userInfo
dictionary.
If your app is in the background and you receive a push notification and the user taps app icon, it brings the application to the foreground.
When that happens, only applicationDidEnterForeground:
is called, and there is no way to access the payload of the push notification.
My requirement is to register for Badge only, no alert so no 'View' button to launch app when user receives notification in background. When user receives notification and application is in background, user taps app icon applicationDidEnterForeground:
is called. So we have no way to access launchOptions
dictionary or userInfo
dictionary from where we can get notification payload.
Am I missing something here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的应用在后台运行,当用户点击状态栏下拉列表中的通知时,会调用
application:didReceiveRemoteNotification:
。您在答案中提到的链接解释了如何使用它。application:didReceiveRemoteNotification:
is called when the user taps on the notification in the statusbar drop down if your app is running in the background. The link you referred to in your answer explains how to use it.