我在同时处理Geofence和用户当前位置时遇到了问题。
当应用程序开始工作时,didUpdateLocations调用得很完美,我有用户所需的位置。
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {但一旦didEnterRegion代表被召唤,
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {}didUpdateLocations不会再开火了。他们有血缘关系吗?
我还检查了
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {}在调用didEnterRegion之后,状态没有更改。我还添加了
locationManager?.startUpdatingLocation()在didEnterRegion中,但是仍然没有调用didUpdateLocations。
有人知道问题出在哪里吗?如何跟踪区域内的位置?
PS:在调用EnterRegion时自动停止更新位置,在调用ExitRegion时自动启动
Update:我使用xCode9、iOS 10、server 4。EnterRegion和ExitRegion都是空的,我现在只需在它们中打印一个日志,它们将在将来向服务器发布一些数据。
发布于 2017-12-16 13:15:15
didUpdateLocations不会再开火了。他们有血缘关系吗?
不!见这里
didChangeAuthorizationStatus在这里毫无意义。授权保持不变。它刚刚被阻止了。
正常跟踪不会对regionMonitoring产生任何影响。它由操作系统管理。
pausesLocationUpdatesAutomatically设置为false,默认设置为trueallowsBackgroundLocationUpdates设置为true。从its的联系:只有在应用程序被挂起时,更新才会停止,从而防止应用程序被唤醒来处理这些事件。
我的猜测是,当你进入一个区域,你的应用程序不再暂停,可以开始跟踪再次,所以你必须确保你的应用程序没有被暂停。要跟踪您可以使用UIApplication.shared.backgroundTimeRemaining。请参阅这个例子
但老实说,我仍然认为你只是犯了一个简单的错误,最终却让你的locationTracking停止了.
https://stackoverflow.com/questions/47843269
复制相似问题