I have a problem with handling Geofence
and user current location at the same time.
When app starts working, didUpdateLocations
called perfectly and I have the user location as desired.
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
But as soon as the didEnterRegion
delegate being called,
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {}
the didUpdateLocations
will not fire anymore.
are they related together?
I also checked the
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {}
the status not changed after didEnterRegion
gets called.
I also added the
locationManager?.startUpdatingLocation()
in didEnterRegion
but still the didUpdateLocations
not gets called.
does anyone know where the problem is? How to track the location in the regions?
PS: updating location automatically stopped when EnterRegion is being called and automatically start when ExitRegion is being called
Update: I use xCode9, iOS 10, swift 4. both the EnterRegion
and ExitRegion
are empty and I just print a log in them now, they're going to post some data to the server in the future.
NO! See here
The
didChangeAuthorizationStatus
is meaningless here. The Authorization stays the same. It's just been stopped.Normal tracking will not have any effect on regionMonitoring. That is managed by the OS.
So perhaps your normal tracking has been stopped due to too much time in the background. To avoid that set
pausesLocationUpdatesAutomatically
tofalse
, the default istrue
Also make sure
allowsBackgroundLocationUpdates
is set totrue
. From the its link:My guess is that the moment you enter a region your app is no longer suspended and can start tracking again, so you have to make sure your app isn't getting suspended. To track that you could do use the
UIApplication.shared.backgroundTimeRemaining
. See this exampleBut to be honest I still think you're just making a simple mistake and somehow end up getting your locationTracking stopped...