Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: CLLocationManager's didEnterRegion not called

I have successfully managed to register a region or monitoring, I know this because the didStartMonitoringForRegion method was fired.

I have a simple test app with one MKMapView where I can see my current location, I also have my region drawn on the map as a red circle so I can actually 'physically' see at what point I am entering or exiting this region. In the didEnterRegion and didExitRegion methods I have a UIAlertView that fires.

A little while ago I decided to leave the office and take a walk with my iPhone 4, to see if this would work. I started in the middle of the region (which is about 200m in radius), my app was in the foreground the whole time. I walked a couple blocks and exited the region, nothing happened.

I read on SO (I think) that sometimes it only works when you exit the region by a certain distance, so I kept on walking.

After another 200m or so I gave up as the UIAlertView still wasn't showing, and started to walk back. Obviously, upon re-entering the region, didEnterRegion wasn't firing either.

I am not calling [locationManager startUpdatingLocation] anywhere in my code, should I be?? I'm only really creating the region and calling [locationManager startMonitoringForRegion].

The CLLocationManagerDelegate is my app delegate, and it seems fine as my didStartMonitoringForRegion is firing properly.

Am I missing anything else?

like image 392
PaulG Avatar asked Nov 03 '22 23:11

PaulG


1 Answers

The documentation states that region monitoring works independently from the other location services. That means it should be enough to call startMonitoringForRegion.

Make sure:

  • [CLLocationManager regionMonitoringAvailable] returns YES
  • CLLocationManager.monitoredRegions contains valid regions

NOTE: The doc specifies that events make take between 3-5 minutes to fire.

In iOS 6, regions with a radius between 1 and 400 meters work better on iPhone 4S or later devices. (In iOS 5, regions with a radius between 1 and 150 meters work better on iPhone 4S and later devices.) On these devices, an app can expect to receive the appropriate region entered or region exited notification within 3 to 5 minutes on average, if not sooner.

And

Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification. It should not expect notifications more frequently than once every five minutes. If the device is able to retrieve data from the network, the location manager is much more likely to deliver notifications in a timely manner.

I hope this helps.

like image 148
Nailer Avatar answered Nov 12 '22 16:11

Nailer