我在我的应用程序中使用核心蓝牙框架。
我知道如何扫描外围设备并从中获取值。(例如心率监视器)
但我想要的是检索支持 BLE 4.0 和蓝牙功能的周围 iPhone 设备列表。
我参考了下面的链接..
使用 IOBluetooth 框架 http://www.ggkf.com/osx/how-to-make-a-drop-down-list-of-available-bluetooth-devices-in-objective-c
使用 CoreBluetooth 获取外设而不是设备列表 https://stackoverflow.com/questions/13062096/how-to-display-the-supported-services-of-bluetooth-in-tableview-from-devicename
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
// I'm not sure how to make this work
NSLog (@"Discovered peripheral: %@", [peripheral name]);
[self.list addObject:peripheral.name]; // add peripheral name to foundarray
NSLog (@"UUID peripheral: %@", [peripheral UUID]);
NSLog (@"peripheral services before connected: %@", [peripheral services]);
NSLog(@"adversting data %@",[NSString stringWithFormat:@"%@",[advertisementData description]]);
NSLog(@"foundArray is %@", self.list);
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
NSLog(@"Central manager's state is updated to: %@", central);
if(central.state == CBCentralManagerStatePoweredOn)
{
//okay your good to go and can now scan
}
else
{
//Unable to use CentralManager methods so print out the central.state and find out why
}
}
不知道苹果有没有提供这个..
任何建议或想法将不胜感激..
预先感谢..
尝试下面的代码checkBluetoothAccess
and requestBluetoothAccess
method
- (void)checkBluetoothAccess {
if(!self.cbManager) {
self.cbManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
/*
We can ask the bluetooth manager ahead of time what the authorization status is for our bundle and take the appropriate action.
*/
CBCentralManagerState state = [self.cbManager state];
if(state == CBCentralManagerStateUnknown) {
[self alertViewWithDataClass:Bluetooth status:NSLocalizedString(@"UNKNOWN", @"")];
}
else if(state == CBCentralManagerStateUnauthorized) {
[self alertViewWithDataClass:Bluetooth status:NSLocalizedString(@"DENIED", @"")];
}
else {
[self alertViewWithDataClass:Bluetooth status:NSLocalizedString(@"GRANTED", @"")];
}
}
- (void)requestBluetoothAccess {
if(!self.cbManager) {
self.cbManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
/*
When the application requests to start scanning for bluetooth devices that is when the user is presented with a consent dialog.
*/
[self.cbManager scanForPeripheralsWithServices:nil options:nil];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)