I am trying to parse the next_question_detail from the push notification but all are fails:
for data in notification.request.content.userInfo {
print(data)
}
//Output
(key: AnyHashable("next_question_detail"), value: {"question_ar":"مرحبا","question":"hi","id":"5"})
(key: AnyHashable("errorCode"), value: 0)
(key: AnyHashable("google.c.a.e"), value: 1)
(key: AnyHashable("body"), value: )
(key: AnyHashable("userId"), value: 4)
(key: AnyHashable("title"), value: Wit)
(key: AnyHashable("gcm.message_id"), value: 0:1528865771984376%fa33e8cdfa33e8cd)
(key: AnyHashable("aps"), value: {
alert = {
body = "";
title = Wit;
};
badge = 0;
sound = default;
})
if let aps = notification.request.content.userInfo["next_question_detail"]! as? NSDictionary {
print("aps",aps)
}
if let data = notification.request.content.userInfo["next_question_detail"] as? [String: String] {
print("array",data)
}
You can do this using following code -
if let userInfo = userInfo as? [String: Any] {
guard let next_question_detail = userInfo["next_question_detail"] as? [String: Any] else {
return
}
print(next_question_detail)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.