I have a problem with regional monitoring when the application is in the background. Regions enter and exit, called if the application is in the foreground, but not in the background (sometimes they work, but very rarely).
How does beacon zone monitoring work for iOS 8.1.1? Should a region instantly go in / out of a fire when it is close in the background?
What to do to make sure it works?
Do Background Modes : Location Updates or Uses Bluetooth LE accessories need to be turned on to monitor the background beacon? GeoFencing worked for me without doing this.
What I have already done:
EDIT:
I created a new project and it still does not work. Here is the code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { _locationManager = [[CLLocationManager alloc] init]; _locationManager.pausesLocationUpdatesAutomatically = NO; _locationManager.desiredAccuracy = 25; _locationManager.delegate = self; [_locationManager requestAlwaysAuthorization]; [_locationManager startUpdatingLocation]; CLBeaconRegion* reg =[self prepareBeacon:@"here i put my UUID" :446 :2196]; [_locationManager startMonitoringForRegion:reg]; [_locationManager startRangingBeaconsInRegion:reg]; return YES; } -(CLBeaconRegion*)prepareBeacon:(NSString*)uuid :(int)maj :(int)min { NSString* identifier = [NSString stringWithFormat:@"%@,%d,%d", uuid, maj, min]; CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:uuid] major:maj minor:min identifier:identifier]; beaconRegion.notifyOnExit=YES; beaconRegion.notifyOnEntry=YES; beaconRegion.notifyEntryStateOnDisplay = YES; return beaconRegion; } -(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region { } -(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { } -(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { } -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { } -(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region { }
Additional Information:
- With the exception of creating a new iOS8 project and adding code, I added the
NSLocationAlwaysUsageDescription file to * .plist. - I set breakpoints in
didEnterRegion and didExitRegion . It works in the foreground, does not work in the background (iPhone on the main screen or locked). - Testing on 4S, iOS 8.1.1
source share