我正在使用Firebase发送多个推送通知。我的应用程序收到所有通知。现在,当应用程序被终止或终止时,如何在用户默认状态下存储所有推送通知数据? 在应用程序被杀死并且用户从所有通知中单击一个推送通知时,如何存储所有推送通知数据?
答案 0 :(得分:0)
您的应用不会仅通过推送通知被调用。通知托盘中收到的内容将直接由iOS处理,而推送通知的内容(特别是通知主体的aps键内部的内容)将用于填充在通知托盘中看到的内容。
仅当您处于挂起或终止状态时,您才会收到推送通知,因此不会调用该应用程序。 当然,除非您在通知中将apns-push-type设置为背景,并且content-available = 1。 通话将转到
application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
您可以在其中根据应用程序的要求处理内容。
要检测该应用是否已从通知中启动,
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
if let dict = launchingOptions?[.remoteNotification]{
//App launched from Notification
if let userInfo = dict as? [AnyHashable:Any]{
//Do what your app requires with the notification using the userInfo.
}
}
}