Search code examples
iosobjective-cbluetoothcllocationmanageribeacon

didEnterRegion()/didExitRegion() never fired while application in the background or device locked


It's a further problem based on the question in iBeacon Bluetooth didEnterRegion and didExitRegion methods are never fired which have been solved.

In detail, the method of didEnterRegion and didExitRegion are never fired while the beacon application in the background or the device locked. In addition, these two methods could be triggered normally while the beacon application in the front.

My application is based on the apple demo "Airlocated (sample code, provided by apple inc)" in the bellow link: https://developer.apple.com/library/ios/samplecode/AirLocate/Introduction/Intro.html#//apple_ref/doc/uid/DTS40013430-Intro-DontLinkElementID_2. I hardly modify any code except adding some code as bellow:

in file "APLAppDelegate.m"

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
    NSLog(@"Entered region: %@", region);

    [self sendLocalNotificationForBeaconRegion:(CLBeaconRegion *)region];
}


- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
    NSLog(@"Exited region: %@", region);
}

in file APLMonitoringViewcontroller.m

- (void)updateMonitoredRegion
{
...

            [self.locationManager startMonitoringForRegion:region];
            [self.locationManager startRangeingForRegion:region];
...
}

Complement a bit. I have tried the bellow methods:

  • Set "Location updates" Background Mode to YES
  • specify notifyOnExit and notifyOnEntry as true
  • reboot iPhone4s with iOS 7.1.2

Could anyone give me some suggestions on it?


Solution

  • How long are you waiting for background detections? Under some circumstances, this can take up to 15 minutes. See here for details.

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