应用程序在后台运行时获取推送通知的自定义负载

发布于 2024-12-01 07:00:09 字数 637 浏览 5 评论 0原文

嘿,有人能告诉我当应用程序处于后台时如何获取推送通知的自定义负载吗?

如果您的应用程序位于后台,并且您收到推送通知,并且用户点击应用程序“查看”,则应用程序将启动,并且将调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心头的小情儿 2024-12-08 07:00:09

如果您的应用在后台运行,当用户点击状态栏下拉列表中的通知时,会调用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文