如何获取CBCentralManager检测到的信标的详细信息

时间:2014-12-04 07:10:34

标签: ios ibeacon

我使用CBCentralManager

检测到了外围设备

我使用的代码就是这个,

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self.navigationController setNavigationBarHidden: YES animated:NO];

    cbMgr = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}


- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {


    //NSLog([NSString stringWithFormat:@"%@",[advertisementData description]]);

    NSLog (@"Discovered peripheral: %@", [peripheral name]);
    NSLog (@"Discovered peripheral identifier: %@", [peripheral identifier]);

    NSLog (@"peripheral services before connected: %@", [peripheral services]);
    NSLog (@"Discovered peripheral RSSI: %@", [peripheral RSSI]);
    NSLog (@"\n===============================================");

   // NSLog(@"adversting data %@",[NSString stringWithFormat:@"%@",[advertisementData description]]);
}

-(void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals{
    NSLog(@"This is it!");
}

- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
    NSString *messtoshow;

    switch (central.state) {
        case CBCentralManagerStateUnknown:
        {
            messtoshow=[NSString stringWithFormat:@"State unknown, update imminent."];
            break;
        }
        case CBCentralManagerStateResetting:
        {
            messtoshow=[NSString stringWithFormat:@"The connection with the system service was momentarily lost, update imminent."];
            break;
        }
        case CBCentralManagerStateUnsupported:
        {
            messtoshow=[NSString stringWithFormat:@"The platform doesn't support Bluetooth Low Energy"];
            break;
        }
        case CBCentralManagerStateUnauthorized:
        {
            messtoshow=[NSString stringWithFormat:@"The app is not authorized to use Bluetooth Low Energy"];
            break;
        }
        case CBCentralManagerStatePoweredOff:
        {
            messtoshow=[NSString stringWithFormat:@"Bluetooth is currently powered off."];
            break;
        }
        case CBCentralManagerStatePoweredOn:
        {
            messtoshow=[NSString stringWithFormat:@"Bluetooth is currently powered on and available to use."];
            [cbMgr scanForPeripheralsWithServices:nil options:nil];
            //[mgr retrieveConnectedPeripherals];

            //--- it works, I Do get in this area!

            break;
        }   

    }
}

现在我想要这样的细节,
公司编号:
信标类型:
接近UUID:
专业:
辅修:
测量功率:

是否有可能获得此详细信息,我尝试使用NSConcreteUUID来设置信标,但它不会返回信标数据(如预期的那样)..

1 个答案:

答案 0 :(得分:2)

很遗憾,您无法使用CoreBluetooth阅读iBeacon信息。 Apple使用这些API阻止访问iBeacon广告的原始数据。你可以在这里阅读有关这方面的全部细节:

http://developer.radiusnetworks.com/2013/10/21/corebluetooth-doesnt-let-you-see-ibeacons.html

访问其中一些数据的最佳方法是使用CoreLocation范围API,但您必须事先了解信标的PriximityUUID才能执行此操作。我怀疑这对您没有用的原因可能是因为您正在使用CoreBluetooth返回的蓝牙服务UUID来使用CoreLocation来定位具有给定ProximityUUID的信标。这不起作用,因为这两个UUID实际上是不同的。

同样,范围是您可以做的最好的,但您将无法读取companyId,beaconType或measuredPower字段。我担心Apple在iOS上阻止访问此信息的工作做得很彻底。

相关问题