didUpdateLocations not being called anymore when didEnterRegion is being called

637 views Asked by At

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.

1

There are 1 answers

8
mfaani On BEST ANSWER

the didUpdateLocations will not fire anymore. are they related together?

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.

Updates stop only when the app is suspended, thereby preventing the app from being woken up to handle those events.

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 example

  • Avoid testing with the simulator. As the app life cycle is a little messed up . See this post from an Apple employee. You have to disconnect from your mac and use logging so you can have a true experience
  • Make sure you see this question. It walks you through some of geofence limitations, I'm not sure how much Apple has improved since then

But to be honest I still think you're just making a simple mistake and somehow end up getting your locationTracking stopped...