我正在尝试解析推送通知中的 next_question_detail ,但都失败了:
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)
}
答案 0 :(得分:0)
您可以使用以下代码执行此操作 -
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)
}