需要解析Apns有效负载并获取用于深度链接的URL。
我试图解析apns的支付负载。它为我提供了具有键aps的字典,并为深度链接url提供了多个键值。每个url字母一个。
func getPushNotificationDeeplink(notificationDictionary: [AnyHashable:Any]) {
print("Notification dictionary = \(notificationDictionary)")
guard let aps = notificationDictionary["aps"] as? [String: AnyObject] else {
return
}
}
结果:
Notification dictionary = [AnyHashable("12"): e, AnyHashable("28"): s, AnyHashable("38"): l, AnyHashable("27"): n, AnyHashable("aps"): {
alert = {
body = "Message 12";
title = "Notification R2";
};
badge = 1;
}, AnyHashable("18"): a, AnyHashable("40"): }, AnyHashable("29"): f, AnyHashable("10"): m, AnyHashable("1"): ", AnyHashable("13"): -, AnyHashable("37"): i, AnyHashable("32"): -, AnyHashable("0"): {, AnyHashable("3"): r, AnyHashable("23"): /, AnyHashable("15"): o, AnyHashable("24"): t, AnyHashable("20"): d, AnyHashable("5"): ", AnyHashable("34"): e, AnyHashable("36"): a, AnyHashable("19"): r, AnyHashable("39"): ", AnyHashable("2"): u, AnyHashable("31"): r, AnyHashable("7"): ", AnyHashable("33"): d, AnyHashable("16"): r, AnyHashable("21"): :, AnyHashable("30"): e, AnyHashable("17"): w, AnyHashable("35"): t, AnyHashable("11"): m, AnyHashable("22"): /, AnyHashable("25"): r, AnyHashable("9"): i, AnyHashable("4"): l, AnyHashable("26"): a, AnyHashable("8"): a, AnyHashable("6"): :, AnyHashable("14"): f]
答案 0 :(得分:0)
您可以尝试
func getPushNotificationDeeplink(notificationDictionary: [AnyHashable:Any]) {
print("Notification dictionary = \(notificationDictionary)")
guard let aps = notificationDictionary["aps"] as? [String: Any] ,
let alert = aps["alert"] as? [String: Any] ,
let body = alert["body"] as? String ,
let title = alert["title"] as? String else {
return
}
print("Body is \(body) Title is \(title)")
}