当使用简单的应用程序测试以测试信标区域监视时,我似乎得到非常不一致的结果,具体取决于设备(不是设备型号,特定设备)。问题是我在CLRegionStateInside
之后没有收到该地区的requestStateForRegion
状态,并且didEnterRegion
在这些设备上根本没有被调用。 startRangingBeaconsinRegion
:工作正常但为了节省电力和处理,建议仅在调用didEnterRegion
:方法时开始测距。我在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];
答案 0 :(得分:4)
我发现了问题。显然,要按照文档中描述的方式使用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.");
}
在这个答案中找到:Detecting user settings for Background App Refresh in iOS 7
答案 1 :(得分:4)
由于多种原因,监控可能无效。一个是应用程序后台刷新被禁用以节省电池。另一个是忽略确保您已设置正确的应用程序功能。
如果这不起作用,那么您可以阅读一篇很棒的帖子,详细说明要排除故障的所有项目。