iOS - 使用 APNS 处理推送通知

发布于 2024-09-08 00:28:06 字数 149 浏览 0 评论 0原文

考虑到我在 iPhone 上收到推送通知。

会发生什么:

  1. 如果应用程序启动:有没有办法获取有效负载?我能在屏幕上看到通知吗?
  2. 如果应用程序没有启动,有没有办法获取payload?

谢谢你的回答

Considering that I receive a pushed notification on my iPhone.

What happens:

  1. If the application is started: is there a way to get the payload? Do I see the notification on my screen?
  2. If the application is not started, is there a way to get the payload?

Thx for your answers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

近箐 2024-09-15 00:28:06

首先,推送通知并不“强”,如果您只是让通知停留足够长的时间(例如手机关闭很多天),它就会被丢弃。您需要执行一些自定义后端处理来保留通知中发送的内容。

UIApplicationDelegate 协议中,有 application:didFinishLaunchingWithOptions:。如果您的应用是通过用户点击推送通知的警报中的右侧按钮来启动的,则绑定到方法调用的 launchOptions 字典将包含有关该通知的信息;如果您的应用程序已经在运行,则将调用 application:didReceiveRemoteNotification: (也在委托协议中)。

因此,

  • 如果应用程序已启动,并且您实现了 application:didReceiveRemoteNotification:,那么您将获得有效负载。否则,什么也不会发生。

  • 如果发送通知时应用程序尚未启动,则用户点击通知警报并启动您的应用程序,如果您的应用程序实现 application:didFinishLaunchingWithOptions:。否则,您什么也得不到。

First of all push notifications are not “strong”, if you simply let a notification sit for long enough (e.g. phone turned off for many days) it will get discarded. You need to do some custom back-end processing to persist the content sent in notifications.

In the UIApplicationDelegate protocol there’s application:didFinishLaunchingWithOptions:. If your app is launched by the user tapping the right button in an alert of a push notification, the launchOptions dictionary bound to the method call will contain information regarding that notification; if your app is already running then application:didReceiveRemoteNotification: (also in the delegate protocol) will get called instead.

So,

  • If the application is started, and you implement application:didReceiveRemoteNotification: then yes you get the payload. Otherwise, nothing happens.

  • If the application is not started at the time the notification is sent, then the user taps on the alert of the notification and launches your app, your app gets the payload if it implements application:didFinishLaunchingWithOptions:. Otherwise, you get nothing.

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