1

I am using FCM for my app. In first build I have successfully added firebase. Then I have upgraded app to new version and it doesn't receive any push notification.

Even firebase server call retruns proper device data, i.e. whether the device is registered or not. Here is the code:

 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()

}

This call gives me fcm details as expected. I have also tried to send notification to single device using fcm token, but It didn't work.

Please Note: It is working perfectly fine on fresh install but not on upgraded one.

KENdi
  • 7,576
  • 2
  • 16
  • 31
  • Are you seeing any patterns on where this occurs? (other than just on fresh installs) Does it occur on specific OS versions only? Is this only occurring on topics or when using the tokens directly as well? – AL. Jul 05 '17 at 13:27
  • @AL. Thanks for the reply. It is occuring in all scenarios. ie.using user segment, topic and tokens directly, but I am unable to get the push while app is in background. I have set priority of notification to *high* as per https://stackoverflow.com/a/37899773/4685283 answer. – Priyanka Wadher Mistry Jul 06 '17 at 09:57
  • I am using firebase notification console to send push notification. My app supports OS 10 and higher version and it is occuring irrespective of specific OS version. – Priyanka Wadher Mistry Jul 06 '17 at 10:00
  • Hi Priyanka. I suggest you reach out to [FIrebase Support](https://firebase.google.com/support/contact/troubleshooting/) to check on this. This seems like an unexpected behavior. But maybe checking the tokens on their side could help. Make sure to include all the details you have (code, testing done, etc). Cheers! – AL. Jul 06 '17 at 10:53
  • 1
    @AL. Yup it seems I need to reach them asap as it is happenig in my production build. btw thanks :) Will update here as I get any solution. – Priyanka Wadher Mistry Jul 06 '17 at 13:32

0 Answers0