我希望我的应用在后台连续更新位置。我已经实现了下面的代码。
locationManager.pausesLocationUpdatesAutomatically =false
self.locationManager = CLLocationManager()
locationManager.requestWhenInUseAuthorization()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
locationManager.allowsBackgroundLocationUpdates=true
locationManager.startMonitoringSignificantLocationChanges()
self.locationManager.startUpdatingLocation()
- 此代码在
appdelegate
didFinishLaunchingWithOptions()
中管理
最佳答案
您需要调用 requestAlwaysAuthorization()
才能接收位置更新,即使您的应用程序在后台运行也是如此。 requestWhenInUseAuthorization()
仅授权您在应用程序在前台运行时接收位置更新。
关于ios - 持续后台更新位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52832444/