iOS - 使用 APNS 处理推送通知
考虑到我在 iPhone 上收到推送通知。
会发生什么:
- 如果应用程序启动:有没有办法获取有效负载?我能在屏幕上看到通知吗?
- 如果应用程序没有启动,有没有办法获取payload?
谢谢你的回答
Considering that I receive a pushed notification on my iPhone.
What happens:
- If the application is started: is there a way to get the payload? Do I see the notification on my screen?
- If the application is not started, is there a way to get the payload?
Thx for your answers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,推送通知并不“强”,如果您只是让通知停留足够长的时间(例如手机关闭很多天),它就会被丢弃。您需要执行一些自定义后端处理来保留通知中发送的内容。
在
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’sapplication:didFinishLaunchingWithOptions:
. If your app is launched by the user tapping the right button in an alert of a push notification, thelaunchOptions
dictionary bound to the method call will contain information regarding that notification; if your app is already running thenapplication: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.