且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AnyHashable:当通过推送通知接收时,Any 不会迅速转换为字典

更新时间:2023-01-16 17:49:36

   //This method will parse push notification userinfo data
    func parseNotification(userInfo: [AnyHashable: Any]) {
        print(">>>parseNotificationCalled ")
        if let notification = userInfo["payload"] as? String,
            let jsonData = notification.data(using: .utf8),
            let dict = try? JSONSerialization.jsonObject(with: jsonData, options: .allowFragments) as? NSDictionary {
            //This is the point where we need to save push notification
            savePushNotification(payloadDict: dict ?? [:])
            print("APS PAYLOAD DICTIONARY \(dict)")
        }

就我而言,有效载荷字典采用字符串格式.解决了.​​

As in my case payload dictionary coming in string format. Solved.