区域监控背景中的信标区域不工作

mic*_*rus 5 iphone core-location ios

当应用程序处于后台时,我遇到了区域监控问题.如果应用程序位于前台,则区域进入和退出会被调用,但在后台时则不会被调用(有时它们会触发但非常罕见).

信标区域监控如何适用于iOS 8.1.1?当在背景中处于Beacon接近时,区域是否应立即进入/退出?

我该怎么做才能确保它有效?

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
{

}
Run Code Online (Sandbox Code Playgroud)

一些额外的信息:

  • 除了创建一个新的iOS8项目并添加我已添加NSLocationAlwaysUsageDescription到*.plist文件的代码.
  • 我把断点放在didEnterRegiondidExitRegion.它在前台工作,在后台无法工作(iPhone在主屏幕或锁定)
  • 在4S,iOS 8.1.1上进行测试

mic*_*rus 3

答案是:后台区域监控对于我们用户来说是一个谜。有时它会在一秒钟内点燃,有时则需要更长的时间。这取决于很多因素,但我的主要问题是我使用的是 iPhone 4s。

也许这会对任何人有所帮助,而不会浪费太多时间:4s 在后台信标扫描方面很糟糕

来源:在两台装有最新 iOS 和 iPhone 6 的 4S 手机上进行测试。iPhone6 在几秒钟内即可收到信标通知。