iOS推送通知: how to store push notification payload when application is kill or terminate in swift?

标签 ios swift

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

最佳答案

您的应用程序不会仅通过推送通知来调用。您在通知托盘中收到的内容由 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.
        }
    }
}

关于iOS推送通知: how to store push notification payload when application is kill or terminate in swift?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59600850/

相关文章:

ios - 用于下载每天更新一次的网页的 URLSessions 或 AlamoFire?

javascript - 如何在 UIAutomation 中使用 Node 模块

ios - 修改 Collection View 单元格内容的图层属性

swift - 如何确定按下了哪个 UIBarButtomSytemItem

ios - 如何知道 UITableView 何时完成 reloadData?

swift - 更改 iOS-Charts 库中的标签大小

ios - 动画时将 UIImageView 置于最前面

objective-c - 创建硬自定义按钮

iphone - 我如何知道应用程序是否被用户终止?

ios - 试图用 Apple Map 填满屏幕