1
votes

I have an iBeacon configured as:

NSUUID *proximityUUID = [[NSUUID alloc] initWithUUIDString:kUUID];
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:proximityUUID identifier:kIdentifier];
self.beaconRegion.notifyEntryStateOnDisplay = NO;    
self.beaconRegion.notifyOnEntry = YES;
self.beaconRegion.notifyOnExit = YES;

When my app is closed and the device is locked, didEnterRegion is never fired:

locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region{
    [self sendLocalNotificationForBeaconRegionHello:(CLBeaconRegion *)region];
}

- (void)sendLocalNotificationForBeaconRegionHello:(CLBeaconRegion *)region
{
    UILocalNotification *notification = [UILocalNotification new];

    notification.alertBody = [NSString stringWithFormat:@"Welcome - %@", region.identifier];
    notification.alertAction = NSLocalizedString(@"View", nil);
    notification.soundName = UILocalNotificationDefaultSoundName;
    notification.fireDate = nil;
    notification.hasAction = false;

    [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}

The didExitRegion does get called even if the app is closed and the phone is locked. I only get a notification when entering a region when unlocking the phone.

Any ideas what might be the problem?

Thanks

1
do you used the keychain somewhere in your start sequence?Daij-Djan
What do you mean with keychain?Antoni
keychain = apple's secure password storageDaij-Djan
No, I don't use the keychain in my app.Antoni

1 Answers

0
votes

I suspect the method is getting called but the notification swallowed for some reason (although the code looks OK). Try adding a method like below to help figure out what is going on:

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
    if(state == CLRegionStateInside) {
        NSLog(@"locationManager didDetermineState INSIDE for %@", region.identifier);
    }
    else if(state == CLRegionStateOutside) {
       NSLog(@"locationManager didDetermineState OUTSIDE for %@", region.identifier);
    }
    else {
        NSLog(@"locationManager didDetermineState OTHER for %@", region.identifier);
    }
}

It would also be useful to see your code in didExitRegion for comparison, and hear details about how you are testing enter/exit conditions (including wait times.)