我有一个区域监控问题,而应用程序在后台。 如果应用程序处于前台,但进入和退出区域被调用,但不在背景中(有时会触发,但很少)。区域监控信标区域在背景不起作用
信标区域监控如何在iOS 8.1.1上工作?当在烽火台附近时,区域应当立即进入/退出火场?
我应该怎么做才能确保它能正常工作?
做Background Modes
:Location Updates
或Uses Bluetooth LE accessories
必须开启背景信标监测工作? GeoFencing在没有这些的情况下为我工作。
我已经做了:
设置这些每一个区域:
beaconRegion.notifyOnExit=YES; beaconRegion.notifyOnEntry=YES; beaconRegion.notifyEntryStateOnDisplay = YES;
- 确信一切都在设置是为了(应用程序刷新等)
编辑:
我创建了一个新项目,但它仍然无法工作。下面的代码:
- (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
{
}
一些额外的信息:
- 除了创造一个新的iOS8上项目,并添加代码我已经添加到
NSLocationAlwaysUsageDescription
*的.plist文件。 - 我把断点放在
didEnterRegion
和didExitRegion
。它工作在前台,而在背景(iPhone在主屏幕或锁定)不起作用 - 测试4S上,的iOS 8.1.1
无需为iBeacons设置背景模式 – 2014-12-12 08:36:19