用户重启手机后如何继续跟踪位置?

我的应用程序需要将位置数据发布到我的后端。 我已将位置权限设置为pausesLocationUpdatesAutomatically ,并为CLLocationManagerpausesLocationUpdatesAutomatically设置为false ,并且即使应用程序处于后台或重新启动手机后,也需要继续跟踪手机位置。

当应用程序处于后台模式时,我能够使它工作。 但是当手机重启时它会停止工作。

我怎样才能做到这一点?

顺便说一句,我知道

Apple文档记录得很好。 只有在使用“startMonitoringSignificantLocationChanges”启动位置管理器时,您才能获得它。

例如:

1)在App委托中启动单例GeoLocationManager.shared.locationManager,因此如果重启将运行。

2)回电:

 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { { 

更新你的位置

如果崩溃,它将是重入的。 我想你已经设置了il plist:

 UIBackgroundModes  location  

注意:添加隐私代码,因为ios9是强制性的..

 func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { ... } 

在plist中:

 NSLocationAlwaysAndWhenInUseUsageDescription Needed to track on maps even if background NSLocationWhenInUseUsageDescription Needed to track on maps even if background