didFinishLaunchingWithOptions

didFinishLaunchingWithOptions

本文介绍了iOS - 使用 APNS 处理推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Considering that I receive a pushed notification on my iPhone.

发生了什么:

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

感谢您的回答

推荐答案

首先,推送通知并不强",如果你只是让一个通知放置足够长的时间(例如手机关闭很多天),它会得到丢弃.您需要进行一些自定义后端处理,以保留通知中发送的内容.

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.

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

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.

所以,

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

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

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

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.

这篇关于iOS - 使用 APNS 处理推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 14:16