我正在通过Google云消息接收远程通知。弹出一条消息,徽章附加到应用程序项目,声音也正常工作。现在我正在尝试访问其他数据,但有点挣扎。这就是消息的样子:
Notification received: [gcm.notification.shops: ["548","525"], gcm.message_id: 0:1472546619970126%1dfec10a1dfec10a, gcm.notification.vibrate: 1, aps: {
alert = {
body = "2 neue Gutscheine verf\U00fcgbar";
title = "Neue Gutscheine";
};
badge = 2;
"content-available" = 1;
sound = 1;
}]
我现在如何访问商店阵列?这不起作用:
var shops :[String] = userInfo["shops"] as! [String]
我正在尝试在didReceiveRemoteNotification()函数中处理它。
答案 0 :(得分:0)
将元素从数组更改为字符串并在最后将其转换为数组就可以了:
if let v = userInfo["gcm.notification.shops"] as? NSString{
let new_vouchers_string = v.componentsSeparatedByString(",")
let new_vouchers = new_vouchers_string.map { Int($0)!}
}