0

我正在通过 Google Cloud Messages 接收远程通知。一条消息弹出,一个徽章附加到应用程序项上,声音也很好。现在我正在尝试访问其他数据,但有点挣扎。这就是消息的样子:

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() 函数中处理它。

4

1 回答 1

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)!}
 }
于 2016-08-30T14:27:23.327 回答