Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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 Swift CLLocationManager STARTMONITORINGMANAGENTLOCATIONCHANGES有时会在重新启动手机时停止工作_Ios_Swift_Core Location_Cllocationmanager_Ios10.3 - Fatal编程技术网

iOS Swift CLLocationManager STARTMONITORINGMANAGENTLOCATIONCHANGES有时会在重新启动手机时停止工作

iOS Swift CLLocationManager STARTMONITORINGMANAGENTLOCATIONCHANGES有时会在重新启动手机时停止工作,ios,swift,core-location,cllocationmanager,ios10.3,Ios,Swift,Core Location,Cllocationmanager,Ios10.3,我使用CLLocationManager从用户那里获取坐标,我需要在后台和设备重新启动时始终获取位置(Uber驱动程序样式)。我使用allowsBackgroundLocationUpdates=true和pausesLocationUpdatesAutomatically=false在后台获取位置,它们工作正常,但当您重新启动手机时,有时CLLocationManager会停止工作 我读过关于startMonitoringSignificantLocationChanges方法的文章,认为这是

我使用CLLocationManager从用户那里获取坐标,我需要在后台和设备重新启动时始终获取位置(Uber驱动程序样式)。我使用allowsBackgroundLocationUpdates=true和pausesLocationUpdatesAutomatically=false在后台获取位置,它们工作正常,但当您重新启动手机时,有时CLLocationManager会停止工作

我读过关于startMonitoringSignificantLocationChanges方法的文章,认为这是重启设备后继续获取位置的唯一方法。但有时有效,有时无效。我读了很多stackoverflows和doc,但我不知道发生了什么

其他失败的方法: a) 我读过关于定时器的书,但是没有办法,因为你可以在前台运行它,或者在后台只运行3分钟。 b) 在安卓系统中,你可以通过广播接收器发送消息唤醒你的应用程序(BOOT_COMPLETED),但在iOS系统中这是不可能的

我认为唯一可能的方法是使用CLLocationManager,但当你重新启动iphone时,它很少有行为。有什么想法吗

这是我的代码:

private lazy var locationManager: CLLocationManager = {
        let manager = CLLocationManager()
        manager.desiredAccuracy = kCLLocationAccuracyBest
        manager.distanceFilter = 100
        manager.pausesLocationUpdatesAutomatically=false
        manager.allowsBackgroundLocationUpdates = true
        manager.delegate = self
        manager.requestAlwaysAuthorization()
        return manager
    }()
我正在使用startUpdatingLocation和startMonitoringSignificantLocationChanges方法进行测试

我正在真实设备上测试(iPhone6plus-iOS10.3)
提前感谢。

我还想在应用程序被禁用或终止时实现相同的行为。我希望在时间间隔内更新位置或更改位置。。。如果您对此有一些解决方案,请帮助我hi@shaqirsaiyed,您可以尝试使用startUpdatingLocation()和startMonitoringSignificantLocationChanges()方法。当您不需要跟踪位置时,不要忘记调用stopUpdateLocation()和stopMonitoringSignificantLocationChanges()。您需要为CLLocationManager设置pausesLocationUpdatesAutomatically=false和allowsBackgroundLocationUpdates=true。这对我有用。小心,因为如果你密集使用GPS跟踪器,可能会耗尽电池电量。我希望你觉得它有用。再见。