我使用以下库来生成推送通知.
https://github.com/edamov/pushok
我得到了推送通知,但我不知道如何在Swift 3中提取响应.
这就是我所拥有的.
// Push notification received func application(_ application: UIApplication,didReceiveRemoteNotification data: [AnyHashable : Any]) { // Print notification payload data print("Push notification received: \(data)") let aps = data[AnyHashable("aps")]! print(aps) }
我可以创建推送通知和控制台消息工作但打印出来…
Push notification received: [AnyHashable("samplekey"): samplevalue,AnyHashable("aps"): { alert = { body = hey; title = "Hello!"; }; sound = default; }] { alert = { body = hey; title = "Hello!"; }; sound = default; }
所以我的问题是如何访问’body’和’title’的alert中的数据?
解决方法
我认为这是一种更安全的方式来做约瑟夫发现的方式.
guard let aps = data[AnyHashable("aps")] as? NSDictionary,let alert = aps["alert"] as? NSDictionary,let body = alert["body"] as? String,let title = alert["title"] as? String else { // handle any error here return } print("Title: \(title) \nBody:\(body)")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。