Voip push Notificationのカスタムペイロードからfrom_idをいうidを受け取り、Stringに変換したいのですが、やり方がわかりません。
swift
1func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) { 2 if (type == .voIP){ 3 print(payload.dictionaryPayload) 4 let id = payload.dictionaryPayload["from_id"] as String 5 } 6 }
[AnyHashable("from_id"): 3, AnyHashable("aps"): { alert = peer; badge = 1; "mutable-content" = 1; sound = default; }] Could not cast value of type '__NSCFNumber' (0x1b78520e0) to 'NSString' (0x1b785ead8). 2018-03-30 08:10:43.711700+0900 calarm[13863:5105171] Could not cast value of type '__NSCFNumber' (0x1b78520e0) to 'NSString' (0x1b785ead8).``` idのところでエラーが出てしまいます。 どうしたらStringに変換できるでしょうか? 追記 ```swift let id = payload["from_id"] as? String
のようにしたらType 'PKPushPayload' has no subscript membersとエラーが出ました。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/03/29 23:37