IBeacon区域监控不能跨设备一致地工作 [英] IBeacon region monitoring not work consistently across devices

查看:132
本文介绍了IBeacon区域监控不能跨设备一致地工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用简单的应用程序测试以测试信标区域监视时,我似乎得到非常不一致的结果,具体取决于设备(不是设备型号,特定设备)。问题是我在 requestStateForRegion 之后的区域内没有收到 CLRegionStateInside 状态didEnterRegion 在这些设备上根本没有被调用。 startRangingBeaconsinRegion :工作正常但为了节省电量和处理,建议仅在 didEnterRegion :方法被调用时开始测距。我在6台设备上进行了测试,它在它们上面工作了一半(iPhone 5)并且不能在一台iPhone 5上运行,一台 5S 和一台 4S

When testing with a simple app to test beacon region monitoring I seem to get very inconsistent results depending on the device (not the device model, the specific device). The problem is that I don't receive the CLRegionStateInside state on the region after requestStateForRegion and didEnterRegion does not get called at all on these device. startRangingBeaconsinRegion: works fine but to conserve power and processing it is recommended to only start ranging when the didEnterRegion: method gets called. I tested this on 6 devices and it works on half on them (iPhone 5's) and does't work on one iPhone 5, one 5S and one 4S.

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

这是设置区域监控的代码

This is the code to setup the region monitoring

    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,用户需要在设置中启用后台刷新设置。要检查此设置,请使用以下代码段:

I Found the problem. Apparently to use iBeacons in the way that is described in the documents users are required to have the Background Refresh setting enabled in the Settings. To check for this setting I use the following snippet:

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.");
}

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

这篇关于IBeacon区域监控不能跨设备一致地工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆