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.