5

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?

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
PaulG
  • 6,920
  • 12
  • 54
  • 98
  • You don't need to call `startUpdatingLocation`. I don't see a problem from what you tell. Maybe it helps when you post some code. – Felix Apr 22 '13 at 17:28
  • Did you verify that inside the region `[monitoredRegion containsCoordinate:mapView.userLocation.location.coordinate]` is true and outside it is false? – Felix Apr 22 '13 at 17:37
  • @phix23 Actually I didn't try that, I will now, thanks! – PaulG Apr 22 '13 at 17:40
  • 1
    @PaulG: have u fixed above issue am getting same problem in my application.can you explain me how you have fixed that – sabir Aug 06 '14 at 14:36
  • @sabir I never got this to work properly so I ended up doing my own distance calculation in the `didUpdateToLocation` method. – PaulG Aug 06 '14 at 17:23
  • @PaulG:For me didenter and didExit regions are never been invoked.. – sabir Aug 07 '14 at 05:49

2 Answers2

2

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.

Nailer
  • 2,446
  • 1
  • 24
  • 34
  • regionMonitoringEnabled is deprecated but I tried it and yes it works. Thanks for the response btw! Hmmm, according to your response I gave up too soon and should have walked further. – PaulG Apr 22 '13 at 17:39
  • 1
    Changed it to regionMonitoringAvailable which is the new call. Btw, check out: http://stackoverflow.com/questions/214416/set-the-location-in-iphone-simulator for an easier way to test this than walking for ages. – Nailer Apr 22 '13 at 17:48
0

One thing to note down (If you are simulating the location):

If entering and exiting is never called even though you think you have done everything right in the code make sure to check if you disabled location simulation by:

Going to the Product -> Scheme -> edit scheme -> Options tab -> Disable location simulation.

I was trying to test my region monitoring by physically walking out and in the region while simulating location and it was not working for me precisely because of this reason.

coletrain
  • 2,809
  • 35
  • 43
npn
  • 103
  • 1
  • 12