IBeacon区域监控不能跨设备一致地工作

Tim*_*rim 5 iphone objective-c core-location ipad ios

当使用简单的应用程序测试以测试信标区域监视时,我似乎得到非常不一致的结果,具体取决于设备(不是设备型号,特定设备).问题是我之后没有收到该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];
Run Code Online (Sandbox Code Playgroud)

Tim*_*rim 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.");
}
Run Code Online (Sandbox Code Playgroud)

在此答案中找到:在 iOS 7 中检测后台应用程序刷新的用户设置