首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何获取CBCentralManager检测到的信标细节

如何获取CBCentralManager检测到的信标细节
EN

Stack Overflow用户
提问于 2014-12-04 07:10:33
回答 1查看 2K关注 0票数 0

我用CBCentralManager检测到外围设备,

我用过的代码是,

代码语言:javascript
运行
复制
- (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;
        }   

    }
}

现在我要这样的细节,

公司ID:

信标类型:

近距离UUID:

主修:

未成年人:

被测功率:

是否有可能得到这个细节,我已经尝试使用NSConcreteUUID对信标进行测距,但它没有返回信标数据(如预期的那样)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-04 12:37:19

不幸的是,您无法使用iBeacon读取CoreBluetooth信息。苹果阻止使用这些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字段。我担心苹果已经做了一个彻底的工作,阻止访问这一信息的iOS。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27288211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档