gpt4 book ai didi

ios - 如何从 IOS swift 中的通知中读取自定义数据

转载 作者:行者123 更新时间:2023-11-28 10:03:55 29 4
gpt4 key购买 nike

我正在构建一个小型 IOS 应用程序,通过 WebKitView 呈现一个网络应用程序。

我需要在 APNS 负载中传递额外的信息来处理应用程序的路由。假设您的帖子有一条新评论。

阅读苹果文档时here .我可以看到可以添加自定义数据。

{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9,
"sound" : "bingbong.aiff"
},
"url" : "https://domain.ext/post/1"
}

我如何访问 url 来自:

    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

// if let page = response.notification["url"] as? String {
// print(url)
// }
completionHandler()
}

最佳答案

你可以试试

let userInfo = response.notification.request.content.userInfo
print(userInfo["url"])

关于ios - 如何从 IOS swift 中的通知中读取自定义数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56932674/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com