Regional beacon monitoring zones do not work

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:

  • set them for each area:

    beaconRegion.notifyOnExit=YES; beaconRegion.notifyOnEntry=YES; beaconRegion.notifyEntryStateOnDisplay = YES;

  • Make sure that everything in the settings is in order (application update, etc.).

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
+5
source share
2 answers

Answer: monitoring the background region is a mystery to users. Sometimes it fires after a second, sometimes it takes more time. It depends on many factors, but my main problem was that I used the iPhone 4s.

Perhaps this will help anyone without losing so much time: 4s sucks when scanning background beacons

source: tested on two 4S phones with the latest iOS and iPhone 6. iPhone6 โ€‹โ€‹receives beacon alerts in seconds.

+2
source

You need to make sure that you call the method under CCLocationManager

 - (void) requestAlwaysAuthorization 

This allows your application to be updated about changes in the foreground and background compared to the line below, which allows you to notify your application only in the foreground:

 - (void) requestWhenInUseAuthorization 

As soon as the user responds to the request, the following method with the updated authorization status will be called:

 - (void) locationManager: (CLLocationManager*) manager didChangeAuthorizationStatus: (CLAuthorizationStatus) status 

Source: https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/cl/CLLocationManager

+2
source

Source: https://habr.com/ru/post/1208664/


All Articles