如何访问(“gcm.notification.data”)值? 我可以使用以下代码访问(“aps”)值:
if let aps = userInfo["aps"] as? NSDictionary {
if let alert = aps["alert"] as? NSDictionary {
if let title = alert["title"] as? NSString,let body = alert["body"] as? NSString{
print(title)
print(body)
}
消息回复
[AnyHashable("gcm.notification.data"): {"status":"7809","body":"sgjh body"},
AnyHashable("aps"): {
alert = {
body = "sgjh body";
title = "yfguhj title";
};
badge = 1;
"content-available" = 1;
sound = default;
}]
最佳答案
if let gcmData = userInfo["gcm.notification.data"] as? NSDictionary {
for (key, value) in gcmData {
guard let key = key as? String else { continue }
switch (key, value) {
case ("status", let aValue as Double): print(aValue)
case ("body", let aValue as String): print(aValue)
default: continue
}
}
}
关于ios - 无法访问 gcm 数据响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52380247/