我用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;
}
}
}
现在我要这样的细节,
公司ID:
信标类型:
近距离UUID:
主修:
未成年人:
被测功率:
是否有可能得到这个细节,我已经尝试使用NSConcreteUUID
对信标进行测距,但它没有返回信标数据(如预期的那样)。
发布于 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。
https://stackoverflow.com/questions/27288211
复制相似问题