ios - 如何从 IOS swift 中的通知中读取自定义数据
问题描述
我正在构建一个小型 IOS 应用程序,通过 WebKitView 呈现 Web 应用程序。
我需要在 APNS 有效负载中传递额外信息来处理应用程序的路由。假设您的帖子有新评论。
在这里阅读苹果文档时。我可以看到可以添加自定义数据。
{
"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"])
推荐阅读
- regex - 在postgres 11中将子字符串与字母数字字符(忽略其他子字符串)匹配
- netlogo - 试图欺骗 NetLogo 执行作为参数传递的函数
- amazon-s3 - 我可以向充当 S3 代理的 AWS API Gateway RestAPI 的请求中发送的最大有效负载大小是多少?
- javascript - 如何使用 jest 返回的 promise 来测试函数?
- rspec - Rspec 共享示例:辅助方法中的访问参数
- python - Cannon Sprites 滞后游戏而不是向玩家旋转
- node.js - 多个验证错误 Aws SDK
- reactjs - React Build Locally 与 Build from CI/CD 不同
- android - javax.net.ssl.SSLHandshakeException:SSL 握手中止:ssl=0x7a83ccb988:系统调用期间的 I/O 错误,对等方重置连接
- mule - 如何在 mule 4 中以编程方式使用 groovy 脚本或 Java SDK 构建流程