Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here are some things to check:</p> <ol> <li><p>Before you start monitoring regions in your code, call <code>[CLLocationManager regionMonitoringAvailable]</code> and <code>[CLLocationManager regionMonitoringEnabled]</code> to make sure the service is available and enabled on the user's phone.</p></li> <li><p>Make sure you have the location manager's <code>delegate</code> property set to the object where you've implemented <code>locationManager:didEnterRegion:</code> and/or <code>locationManager:didExitRegion:</code>.</p></li> <li><p>Make sure you don't have any typos in those method signatures. A small capitalization error would cause delivery of these messages to fail. Copy/paste these into your code and make sure they match:</p> <pre><code>- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { /* Handle enter */ } - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { /* Handle exit */ } </code></pre></li> <li><p>Make sure your delegate also implements <code>locationManager:monitoringDidFailForRegion:withError:</code>, as it may tell you why the service is failing.</p> <pre><code>- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error { NSLog(@"Region monitoring failed with error: %@", [error localizedDescription]); } </code></pre></li> <li><p>One reason a monitoring failure like this may occur is that Core Location imposes a limit on the number of regions an app is allowed to monitor. In practice this limit seems to be about ten regions per app. So make sure you remove regions you don't need using <code>stopMonitoringForRegion:</code>, and monitor only those regions nearest the user as recommended by Apple's <a href="http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html#//apple_ref/doc/uid/TP40009497-CH2-SW13" rel="noreferrer">Location Awareness Programming Guide</a>:</p> <blockquote> <p>You should always be judicious when specifying the set of regions to monitor. Regions are a shared system resource and the total number of regions available systemwide is limited. For this reason, Core Location limits the number of regions that may be simultaneously monitored by a single application. To work around these limits, you should consider registering only those regions in the user’s immediate vicinity. As the user’s location changes, you can remove regions that are now farther way and add regions coming up on the user’s path. If you attempt to register a region and space is unavailable, the location manager calls the <code>locationManager:monitoringDidFailForRegion:withError:</code> method of its delegate with the <code>kCLErrorRegionMonitoringFailure</code> error code.</p> </blockquote></li> <li><p>Hopefully obvious, but make sure you're calling <code>startMonitoringForRegion:desiredAccuracy:</code> after setting your delegate.</p></li> <li><p>When you initialize the <code>CLRegion</code> object that you're monitoring using <code>initCircularRegionWithCenter:radius:identifier:</code>, make sure you use a unique identifier for each region.</p></li> <li><p>If your <code>locationManager:didEnterRegion:</code> and <code>locationManager:didExitRegion:</code> methods are getting called properly when the app is active, but not when the OS relaunches your app in the background after it's been killed, then you may not be properly initializing your location manager and setting its delegate in that case. If you cross a registered region boundary when the app isn't running, the OS will launch your app in the background, which you can detect using <code>if ([launchOptions objectForKey:@"UIApplicationLaunchOptionsLocationKey"]]) {}</code> in the <code>application:didFinishLaunchingWithOptions:</code> method of your app delegate. Your app probably won't load any views when it's launched in the background like this, so you need to make sure <code>application:didFinishLaunchingWithOptions:</code> invokes some code path that instantiates your location manager object and sets its delegate in this case. As soon as your location manager's delegate property gets set, any pending region monitoring events will be delivered.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload