iOS - Regionmonitoring in StandBy

76 views Asked by At

I´ve implemented a monitoring function for beacons (didEnterRegion). It works great if I use my iPhone. (App is in foreground, background or only installed and closed but my iPhone has to be in use (screen on).)

If my phone is in standBy mode (top button pressed), I get no notification with didEnterRegion. If I use my phone (screen on), the notification pop up. Is there an opportunity to get the didEnterRegion event also in the standby mode?

self->beaconLocationManager = [[CLLocationManager alloc] init];
[self->beaconLocationManager requestAlwaysAuthorization];
self->beaconLocationManager.delegate = self;
beaconLocationManager.allowsBackgroundLocationUpdates = YES;
NSString* beaconIdentName = [NSString stringWithFormat:@"Beacon%d", cnt];
NSUUID *uuid2=[[NSUUID alloc]initWithUUIDString:uuid];
clBeconRegion2=[[CLBeaconRegion alloc]initWithProximityUUID:uuid2 identifier:beaconIdentName];
clBeconRegion2.notifyOnEntry=YES;
clBeconRegion2.notifyEntryStateOnDisplay = NO;
[self->beaconLocationManager startMonitoringForRegion:clBeconRegion2];
[self->beaconLocationManager startRangingBeaconsInRegion:clBeconRegion2];

...

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    NSLog(@"ENTER REGION");
    UILocalNotification *localNotification = [[UILocalNotification alloc]init];
    localNotification.alertBody = @"FOUNDED";
    localNotification.alertAction = [NSString stringWithFormat:@"%@ Connecting...", region.identifier];
    [[UIApplication sharedApplication]presentLocalNotificationNow:localNotification];
}

Project settings: Push notifications are on. Background modes for location updates, backgroudn fetch, uses bluetooth LE accessories are on.

Tested on iOS 11.1

2

There are 2 answers

1
Niraj On

How long have you waited for background detection? This can take up to 15 minutes.

See here for details: http://developer.radiusnetworks.com/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html

As described in that article, you do not need to set location updates Background Mode to YES. Also you don't need to specify notifyOnExit and notifyOnEntry as true.

Hope this may help.

0
davidgyoung On

The behavior described in the question is unusual and it does not match my experience of what I see on devices. You are absolutely supposed to get didEnterRegion calls with a dark screen, and I have several apps on iOS 7-11.x where I have seen this happen.

The code shown looks good, and I don't even know a way to cause the behavior you describe even if you wanted to. There must be some other unknown variable that is causing this unusual behavior on your phone. I might try testing on a different phone, verifying you do not see this behavior, then using trial and error to try and make the phones' configurations identical until you figure out what the missing variable is.

Sorry, I know this is not an easy answer.