2016-08-30 44 views
0

我正在通過Google雲消息接收遠程通知。一條消息彈出,一個徽章附加到應用程序項目,也聲音工作正常。現在我試圖訪問額外的數據,但有點掙扎。這就是消息的樣子:如何處理iOS遠程消息中的其他數據GCM

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

從數組改變元件爲字符串的把它變成在最後一個數組並達到目的:

if let v = userInfo["gcm.notification.shops"] as? NSString{ 
    let new_vouchers_string = v.componentsSeparatedByString(",") 
    let new_vouchers = new_vouchers_string.map { Int($0)!} 
}