How to reset region center when exited region in background using CoreLocation

My idea is simple in theory, but am having a really hard time executing it. I want to create a geofence at the user's location, and when the user exits that region, I want to recenter the region at the user's updated location. Here is the flow:

  • Retrieve user's currently location using standard [CLLocationManager startUpdatingLocation]
  • On locationManager:didUpdateLocations:, create a geofence at the current location using startMonitoringForRegion, and on subsequent location updates, recenter that region
  • On locationManager:didExitRegion:, which is usually called from the background to wake up the app, call [CLLocationManager startUpdatingLocation] to retrieve the user's current location to recenter the geofence (centered to the next updated location that is NOT the current region center coordinate).
  • Sometimes this all works, but more often than not, the geofence doesn't recenter correctly. What's been happening is that the region is re-centered and locationManager:didExitRegion: is immediately called, which puts it into an infinite loop until the app is terminated again. Since it is terminated without a valid monitored region, the app then won't be woken up for location updates.

    Is this incorrect usage of region monitoring? I'm trying to play with different ways of tracking user location in a battery efficient way (and not constantly using the standard startUpdatingLocation). Would a combination of signification location change tracking and visit monitoring be more effective?

    Thanks!

    链接地址: http://www.djcxy.com/p/20352.html

    上一篇: .NET 4 Windows服务安装升级错误

    下一篇: 如何使用CoreLocation在后台退出区域时重置区域中心