iOS推送通知:当应用程序被杀死或迅速终止时,如何存储推送通知有效载荷?

问题描述 投票:0回答:1

我正在使用Firebase发送多个推送通知。我的应用程序收到所有通知。现在,当应用程序被终止或终止时,如何在用户默认状态下存储所有推送通知数据?当应用程序被杀死并且用户从所有通知中单击一个推送通知时,如何存储所有推送通知数据?

ios swift
1个回答
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.
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.