IBeacon区域监视在设备间不一致

当testing一个简单的应用程序来testing信标区域监控,我似乎得到非常不一致的结果取决于设备(不是设备型号,特定的设备)。 问题是,在requestStateForRegion之后,我没有在区域上收到CLRegionStateInside状态, didEnterRegion在这些设备上根本没有被调用。 startRangingBeaconsinRegion :工作正常,但为了节约能源和处理,build议只在didEnterRegion :方法被调用时才开始测距。 我testing了这个在6个设备上,它在他们的一半(iPhone 5的),并没有在一个iPhone 5,一个5S和一个4S

我使用的信标是kontakt.io信标。

这是设置区域监视的代码

  self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:BEACON_UUID]; CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"regionIdentifier"]; region.notifyOnEntry = YES; region.notifyOnExit = YES; region.notifyEntryStateOnDisplay = YES; [self.locationManager startMonitoringForRegion:region]; [self.locationManager requestStateForRegion:region]; //If I enable this line, ranging starts on all devices // [self.locationManager startRangingBeaconsInRegion:region]; 

我发现了这个问题。 显然,要按照文档中描述的方式使用iBeacons,用户需要在“设置”中启用“后台刷新”设置。 要检查这个设置,我使用下面的代码片段:

 if ([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusAvailable) { NSLog(@"Background updates are available for the app."); }else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusDenied) { NSLog(@"The user explicitly disabled background behavior for this app or for the whole system."); }else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusRestricted) { NSLog(@"Background updates are unavailable and the user cannot enable them again. For example, this status can occur when parental controls are in effect for the current user."); } 

在这个答案中find: 在iOS 7中检测后台应用程序刷新的用户设置

监视可能有几个原因不起作用。 一个是应用程序背景刷新被禁用,以节省您的电池。 另一个是忽略确保你已经设置了正确的应用程序function。

背景模式

如果这不起作用有一个伟大的职位,你可以阅读详细的所有项目进行疑难解答。

iBeacon StartMonitoringForRegion不起作用