Note that there are some explanatory texts on larger screens.

plurals
  1. POdidEnterRegion works in foreground but not background or other VCs
    primarykey
    data
    text
    <p>If the app is running and the CLLocationManagerDelegate class is the foreground (i.e. visible) then the didEnterRegions triggers and I get both the NSLog as well as the AlertView. However, I get nothing when the app is in the background or, essentially, if the screen is showing anything but the delegate class.</p> <p>I have set "App registers for location updates" under "Required background modes" in the plist although I'm not sure that's even necessary.</p> <p>Here's what I think is the relevant code although I may be wrong (and will gladly add more). I should note that everything in viewDidLoad is wrapped in an if which checks if region monitoring is available and enabled.</p> <pre><code>- (void)viewDidLoad { NSLog(@"MapViewController - viewDidLoad"); self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; self.locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters; self.locationManager.delegate = self; [self.locationManager startMonitoringSignificantLocationChanges]; } - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { NSLog(@"MapViewController - didEnterRegion"); NSLog(@"MVC - didEnterRegion - region.radius = %f", region.radius); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"entered region..." message:@"You have Entered the Location." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; alert.tag = 2; [alert show]; } </code></pre> <p>here is where I get the list of regions being monitored, in AppDelegate.m:</p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // other code NSLog(@"LISTING ALL REGIONS MONITORED"); NSArray *regions = [self.locationManager.monitoredRegions allObjects]; if (!regions) { NSLog(@"no regions found"); } else { NSLog(@"got %d monitored regions", [regions count]); for (int i = 0; i &lt; [regions count]; i++) { CLRegion *region = [regions objectAtIndex:i]; NSLog(@"region %d's identifier = %@", i, region.identifier); NSLog(@"region: radius: %@", region.radius); } } // other code } </code></pre> <p>I call startMonitoringForRegion twice, here's the main place:</p> <pre><code>- (void)doneButtonTapped { NSLog(@"doneButtonTapped"); if (self.locationIdentifier) { if ([CLLocationManager regionMonitoringEnabled] &amp;&amp; [CLLocationManager regionMonitoringAvailable]) { // core data setup NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"LocationReminder" inManagedObjectContext:self.managedObjectContext]; fetchRequest.entity = entityDescription; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"locationIdentifier == %@", self.locationIdentifier]; fetchRequest.predicate = predicate; NSError *error; NSArray *results = [self.managedObjectContext executeFetchRequest:fetchRequest error:&amp;error]; if (results) { // get the LocationReminder LocationReminder *retrievedReminder = [results objectAtIndex:0]; retrievedReminder.audioURI = [[[self.audioPlayers objectAtIndex:self.selectedCell] url] absoluteString]; retrievedReminder.userRecording = nil; // start monitoring it's region NSArray *coordinateArray = [retrievedReminder.locationIdentifier componentsSeparatedByString:@", "]; CLLocationCoordinate2D coordinate = {[[coordinateArray objectAtIndex:0] doubleValue], [[coordinateArray objectAtIndex:1] doubleValue]}; CLRegion *newRegion = [[CLRegion alloc] initCircularRegionWithCenter:coordinate radius:250.0 identifier:retrievedReminder.locationIdentifier]; NSLog(@"about to monitor region with radius: %f", newRegion.radius); [self.locationManager startMonitoringForRegion:newRegion desiredAccuracy:kCLLocationAccuracyBest]; // save the LocationReminder if (![self.managedObjectContext save:&amp;error]) { NSLog(@"hmm. no managed object context. must be something space-time going on"); } else { NSLog(@"saved locationReminder, locationIdentifier = %@", retrievedReminder.locationIdentifier); } } else { NSLog(@"ERROR: no LocationReminder retreived for predicate: %@", predicate); } } // get the mapview controller off of the navigation stack for (UIViewController *viewController in self.navigationController.viewControllers) { if ([viewController isKindOfClass:[MapViewController class]]) { MapViewController *mapVC = (MapViewController *)viewController; mapVC.audioURI = [[[self.audioPlayers objectAtIndex:self.selectedCell] url] absoluteString]; [self.navigationController popToViewController:mapVC animated:YES]; } } } </code></pre> <p>And because I get the feeling that it might be important, here's the getter for locationManager:</p> <pre><code>- (CLLocationManager *)locationManager { NSLog(@"MapViewController - locationManager"); if (_locationManager) { return _locationManager; } else { _locationManager = [[CLLocationManager alloc] init]; return _locationManager; } } </code></pre> <p><strong>UPDATE 1:</strong> Via the Apple forums (where I crossposted) someone mentioned that AlertView will only show in the foreground. Still the NSLog doesn't fire either. I'm assuming that should work.</p>
    singulars
    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.
 

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