我使用以下库来生成推送通知. https://github.com/edamov/pushok 我得到了推送通知,但我不知道如何在Swift 3中提取响应. 这就是我所拥有的. // Push notification received func application(_ application: UIApp
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)")
