应用程序后FCM无法接收推送通知

时间:2017-07-04 12:45:31

标签: ios firebase swift3 push-notification firebase-cloud-messaging

我在我的应用中使用FCM。在第一次构建中,我已经成功添加了firebase。然后我将应用升级到新版本,并且它没有收到任何推送通知。

即使firebase服务器调用也会重新设置正确的设备数据,即设备是否已注册。这是代码:

 func getUserTopicSubscribeWithToken() {
    print("getUserTopicSubscribeWithToken")

    var token = ""
    if Messaging.messaging().fcmToken != nil {
        token = Messaging.messaging().fcmToken!
    }
    let urlString = "https://iid.googleapis.com/iid/info/\(token)?details=true"
    let url = URL(string: urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!)
    var request = URLRequest(url: url!)
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    request.setValue("key=\(serverKey)", forHTTPHeaderField: "Authorization")

    let session = URLSession.shared
    session.dataTask(with: request) {data, response, err in
        print("Entered the completionHandler")
        if (data != nil && err == nil) {
            if let topics = String.init(data: data!, encoding: .utf8) {
                print("topics :: \(topics)")
                let cleanResult = topics.replacingOccurrences(of: "\\", with: "")
                if let dict = JSONResultHelper.convertToDictionary(text: cleanResult) {
                    print("dict :: \(dict)")

                    if let allTopics = dict["rel"] as? [String:Any] {
                        print("allTopics :: \(allTopics)")
                        if let values = allTopics["topics"] as? [String:Any] {
                            print("values :: \(values)")
                                for key in values.keys {
                                AppDelegate.sharedInstance.moduleManager().apiModule?.subscribeToChannel(channelName: key)
                            }
                        }
                    }
                }
            }
        }

        }.resume()

}

此调用按预期为我提供了fcm详细信息。 我也尝试使用fcm令牌向单个设备发送通知,但它没有用。

请注意: 它在全新安装时工作得很好,但在升级后却没有。

0 个答案:

没有答案