I create an application in flutter for update the current location of user while device receive a silent push notification. Its working fine in Android and IOS. But in iOS (only app killed/terimtaed stage) after updating the location when the silent push notification receive, the device fcm token automatically changed. Why this happened? I think its security issue in IOS. The code I written in AppDelegate is given below.
Code Block public override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { if let myData = userInfo["ids"] as? NSString { fcmUSerId = myData } locationManager?.allowsBackgroundLocationUpdates = true Messaging.messaging().delegate = self setupLocationManager() locationManager.delegate = self completionHandler(UIBackgroundFetchResult.newData) } func setupLocationManager(){ locationManager = CLLocationManager() locationManager.allowsBackgroundLocationUpdates = true self.locationManager?.requestAlwaysAuthorization() locationManager?.desiredAccuracy = kCLLocationAccuracyNearestTenMeters locationManager?.startUpdatingLocation() locationManager.pausesLocationUpdatesAutomatically = false } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { print("location start background") let locationValue:CLLocationCoordinate2D = manager.location!.coordinate print("locations = \(locationValue)") let date : Date = Date() let dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy hh:mm a" let todaysDate = dateFormatter.string(from: date) let db=Firestore.firestore() Messaging.messaging().delegate = self let token = Messaging.messaging().fcmToken print("FCM token: \(token ?? "")") db.collection("users").document(fcmUSerId! as String).setData(["startTime": todaysDate,"lastStatus": "Updated","latitude":locationValue.latitude,"longitude":locationValue.longitude,"deviceid":token],merge: true) locationManager?.stopUpdatingLocation() }