Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 是否可以使用目标C扫描位置服务禁用的信标?_Ios_Bluetooth_Location Services_Beacon - Fatal编程技术网

Ios 是否可以使用目标C扫描位置服务禁用的信标?

Ios 是否可以使用目标C扫描位置服务禁用的信标?,ios,bluetooth,location-services,beacon,Ios,Bluetooth,Location Services,Beacon,如果蓝牙和定位服务打开,我能够成功扫描信标。但我想知道,当蓝牙处于开启模式,而定位服务处于关闭模式时,是否有任何方法可以扫描信标 我使用过这段代码,但在位置服务关闭时不会调用此委托方法 -(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region 有人能详细说明一下我们如何在没有定位服务的情况下扫描信标吗 提前感谢

如果蓝牙和定位服务打开,我能够成功扫描信标。但我想知道,当蓝牙处于开启模式,而定位服务处于关闭模式时,是否有任何方法可以扫描信标

我使用过这段代码,但在位置服务关闭时不会调用此委托方法

-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region 
有人能详细说明一下我们如何在没有定位服务的情况下扫描信标吗


提前感谢。

不,我认为在位置服务关闭的情况下,您不能使用系统iBeacon支持。iBeacon支持由核心位置框架提供


您可能可以编写低级的BLE代码来查找来自iBeacons的消息,但我看到过一些人的帖子,他们不知道如何做到这一点。此外,您将失去核心位置提供的好处,例如即使在检测到信标时您的应用程序未运行,也会收到有关信标的通知。

不,没有位置服务,您无法使用iBeacon。查看苹果公司文档中对此的描述:

iBeacon与iOS中的定位服务一起工作。使用iBeacon,您的iOS 当您接近或离开某个位置时,该设备可以向应用程序发出警报。在里面 除了监控你的位置,应用程序还能知道你何时接近 到iBeacon,比如零售店的收银台。而不是 iBeacon使用纬度和经度来确定您的位置 iOS设备检测到的蓝牙低能量信号

有关更多详细信息,请阅读


希望这会有所帮助:)

在蓝牙打开但位置关闭的情况下,您只能使用
CoreBluetooth
API检测蓝牙LE信标设备,而不能使用
CoreLocation
API检测蓝牙LE信标设备。

这有效地防止了您检测iBeacon传输,因为iOS通过
CoreBooth
阻止了它们的检测。请参见我的博客帖子:

但是,您可以使用
corebooth
检测其他信标格式,如AltBeacon和Eddystone。我有开源代码展示了如何使用

使用上述工具,以下是扫描AltBeacon、Eddystone UID、Eddystone URL和Eddystone EID并记录检测到的标识符的示例:

self.beaconParsers = [[NSMutableArray alloc] init];
RNLBeaconParser *altBeaconParser = [[RNLBeaconParser alloc] init];
[altBeaconParser setBeaconLayout:@"m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25" error: Nil ];
RNLBeaconParser *uidBeaconParser = [[RNLBeaconParser alloc] init];
[uidBeaconParser setBeaconLayout:@"s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19" error: Nil];
RNLBeaconParser *urlBeaconParser = [[RNLBeaconParser alloc] init];
[urlBeaconParser setBeaconLayout:@"s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-20v" error: Nil];
RNLBeaconParser *eidBeaconParser = [[RNLBeaconParser alloc] init];
[eidBeaconParser setBeaconLayout:@"s:0-1=feaa,m:2-2=30,p:3-3:-41,i:4-11" error: Nil];
self.beaconParsers = @[ altBeaconParser, uidBeaconParser, urlBeaconParser, eidBeaconParser ];
self.cbManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()
                                                  options:@{ CBCentralManagerOptionRestoreIdentifierKey:
                                                               @"myCentralManagerIdentifier" }];

...

- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
  if (central.state == CBCentralManagerStatePoweredOn && self.scanning) {
    CBUUID *eddystone16BitUUID = [CBUUID UUIDWithString:@"FEAA"];
    NSLog(@"eddy uuid is %@", [eddystone16BitUUID UUIDString]);
    [self.cbManager scanForPeripheralsWithServices:@[eddystone16BitUUID] options:@{CBCentralManagerScanOptionAllowDuplicatesKey : @(YES)}];
    // this scans for BLE peripherals including beacons
    [self.cbManager scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey : @(YES)}];

  }
  else {
    if (central.state == CBCentralManagerStateUnknown) {
      NSLog(@"CoreBluetooth state UNKNOWN");
    }
    else if (central.state == CBCentralManagerStateResetting)  {
      NSLog(@"CoreBluetooth state RESETTING");
    }
    else if (central.state == CBCentralManagerStateUnsupported)  {
      NSLog(@"CoreBluetooth state UNSUPPORTED");
    }
    else if (central.state == CBCentralManagerStateUnauthorized)  {
      NSLog(@"CoreBluetooth state UNAUTHORIZED");
    }
    else if (central.state == CBCentralManagerStatePoweredOff)  {
      NSLog(@"CoreBluetooth state POWERED OFF");
    }
  }
}


- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
  NSDictionary *serviceData = advertisementData[@"kCBAdvDataServiceData"];

  RNLBeacon *beacon = Nil;
  NSData *adData = advertisementData[@"kCBAdvDataManufacturerData"];

  for (RNLBeaconParser *beaconParser in self.beaconParsers) {
    if (adData) {
      beacon = [beaconParser fromScanData: adData withRssi: RSSI forDevice: peripheral serviceUuid: Nil];
      beacon.bluetoothIdentifier = [peripheral.identifier UUIDString];
    }
    else if (serviceData != Nil) {
      for (NSObject *key in serviceData.allKeys) {
        NSString *uuidString = [(CBUUID *) key UUIDString];
        NSScanner* scanner = [NSScanner scannerWithString: uuidString];
        unsigned long long uuidLongLong;

        [scanner scanHexLongLong: &uuidLongLong];
        NSNumber *uuidNumber = [NSNumber numberWithLongLong:uuidLongLong];

        NSData *adServiceData = [serviceData objectForKey:key];
        if (adServiceData) {
          beacon = [beaconParser fromScanData: adServiceData withRssi: RSSI forDevice: peripheral serviceUuid: uuidNumber];
        }
      }
    }
    if (beacon != Nil) {
      break;
    }
  }

  if (beacon != Nil) {
    NSString *key = [NSString stringWithFormat:@"%@ %@ %@", beacon.id1, beacon.id2, beacon.id3];
    NSLog(@"Detected beacon: %@", key);
}

是的,我想你可以。谢谢你的回答。但谷歌Crome如何在位置服务关闭的情况下扫描信标呢?我们可以在Crome的小部件中看到最近的信标。你能分享一些想法吗?我怀疑他们有自己的BLE库来检测iBeacons。但Crome小部件能够扫描IBeacon,即使位置服务关闭。你能分享一下你的知识吗?Chrome小部件会扫描Eddystone URL传输,而不是iBeacon传输。这就是为什么在没有核心定位的情况下这是可能的。在这里查看更多:查看我的答案编辑,并链接到测试,证明您无法使用CoreBluetooth检测iBeacon,以及使用CoreBluetooth检测其他信标格式的代码。非常感谢。您能告诉我如何使用CoreBluetooth框架扫描Eddystone信标吗?很抱歉,您无法扫描iOS上具有公共API的所有iBeacon UUID。苹果故意不允许这样做。