如何获取CBCentralManager检测到的信标的详细信息 [英] How to get the detail for beacon detected by CBCentralManager

查看:78
本文介绍了如何获取CBCentralManager检测到的信标的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 CBCentralManager 检测到了外围设备,

I have detected Peripheral devices using 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:
专业:
次要:
实测功率:

Now i want detail like this,
Company ID:
Beacon Type:
Proximity UUID:
Major:
Minor:
Measured Power:

是否有可能获得此详细信息,我尝试使用 NSConcreteUUID 定位信标,但是它不返回信标数据(按预期方式)..

Is it possible to get this detail, I have tried to range beacon using the NSConcreteUUID but it does not return beacon data (as expected)..

推荐答案

不幸的是,您无法使用 CoreBluetooth 读取iBeacon信息.Apple使用这些API阻止访问iBeacon广告的原始数据.您可以在此处阅读有关此内容的完整详细信息:

Unfortunately, you cannot read iBeacon info using CoreBluetooth. Apple blocks access to the raw data of iBeacon advertisements using these APIs. You can read full details about this here:

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

要访问其中的某些数据,最好的方法是使用 CoreLocation 范围内的API,但是您必须预先知道信标的PriximityUUID.我怀疑这对您不起作用的原因可能是因为您正在使用 CoreBluetooth 返回的蓝牙服务UUID来使用 CoreLocation 定位具有给定ProximityUUID的信标.这将不起作用,因为这两个UUID实际上是不同的.

The best you can do to access some of these data is to use the CoreLocation ranging APIs, but you must know the PriximityUUID of the beacon up front to do this. I suspect the reason this has not worked for you may be because you are using the Bluetooth service UUID returned by CoreBluetooth to range for beacons with a given ProximityUUID using CoreLocation. This will not work, because these two UUIDs are actually different.

同样,范围调整是您可以做到的最好的选择,但是您将无法读取companyId,beaconType或measuredPower字段.恐怕苹果公司已经做了彻底的工作,阻止在iOS上访问此信息.

Again, ranging is the best you can do, but you will not be able to read the companyId, beaconType or measuredPower fields. I am afraid Apple has done a thorough job of blocking access to this info on iOS.

这篇关于如何获取CBCentralManager检测到的信标的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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