Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios FCM令牌在收到静默推送通知时在更新位置后自动更改_Ios_Firebase_Flutter_Firebase Cloud Messaging - Fatal编程技术网

Ios FCM令牌在收到静默推送通知时在更新位置后自动更改

Ios FCM令牌在收到静默推送通知时在更新位置后自动更改,ios,firebase,flutter,firebase-cloud-messaging,Ios,Firebase,Flutter,Firebase Cloud Messaging,我在flatter中创建了一个应用程序,用于在设备接收静默推送通知时更新用户的当前位置。它在Android和IOS中运行良好。但在iOS(仅应用程序终止/终止阶段)中,在收到静默推送通知时更新位置后,设备fcm令牌会自动更改。为什么会这样?我认为它在IOS中存在安全问题。下面给出了我在AppDelegate中编写的代码 public override func application(_ application: UIApplication, didReceiveRemoteNotific

我在flatter中创建了一个应用程序,用于在设备接收静默推送通知时更新用户的当前位置。它在Android和IOS中运行良好。但在iOS(仅应用程序终止/终止阶段)中,在收到静默推送通知时更新位置后,设备fcm令牌会自动更改。为什么会这样?我认为它在IOS中存在安全问题。下面给出了我在AppDelegate中编写的代码

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