我正在开发一个具有信标区域监控的应用程序。下面是监控信标区域的代码。
-(void)setBeaconMonitoringForUUID:(NSString *)strID withMajor:(NSString *)strMajor withMinor:(NSString *)strMinor withIdentifier:(NSString *)strIdentifier {
NSUUID *strUUID = [[NSUUID alloc] initWithUUIDString:strID];
CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:strUUID major:[strMajor intValue] minor:[strMinor intValue] identifier:strIdentifier];
[beaconRegion setNotifyEntryStateOnDisplay:YES];
[beaconRegion setNotifyOnEntry:YES];
[beaconRegion setNotifyOnExit:YES];
[self.objLocationManager startMonitoringForRegion:beaconRegion];
[self.objLocationManager startRangingBeaconsInRegion:beaconRegion];}
locationManager初始化如下
- (id)init
{
self = [super init];
if (self != nil)
{
self.objLocationManager = [CLLocationManager new];
self.objLocationManager.delegate = self;
self.objLocationManager.distanceFilter = 10.0;
self.objLocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
self.objLocationManager.allowsBackgroundLocationUpdates = YES;
if ([self.objLocationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.objLocationManager requestAlwaysAuthorization];
}
[self.objLocationManager startUpdatingLocation];
}
return self;
}
现在的问题是要监控信标区域,iOS 设备必须启用蓝牙或在不打开蓝牙的情况下工作?我也引用了以下链接,但没有关于启用蓝牙进行区域监控的解释 Determining the Availability of Region Monitoring
我已经用 kontakt.io beacon 进行了测试,如果不打开设备上的蓝牙它就无法工作,但是当我读到区域监控正在定位服务上工作时,那么为什么我们需要启用蓝牙。所以每个信标都需要打开蓝牙或它特定于 kontakt.io 信标?
最佳答案
Apple 在 iOS 11 中做出更改,即使用户在控制中心禁用蓝牙,操作系统仍会执行 iBeacon 设备的扫描和检测。 (控制中心是您通过从 iOS 屏幕底部向上滑动获得的快速访问 Pane 。)有关更多详细信息,请参见此处:https://support.apple.com/en-us/HT208086
上述说法不适用于 iOS 10.x 及更早版本,在控制中心关闭蓝牙将禁用信标检测。正如 @Paulw11 在他的回答中指出的那样,您还必须在手机上启用定位功能,并且该应用程序必须先从该应用程序获得动态位置许可,然后才能检测到信标。
同样在所有版本的 iOS 上,如果您转到“设置”->“蓝牙”并禁用蓝牙,它将禁用信标检测。
关于iOS beacon 区域监控需要开启蓝牙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47069117/