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