Iphone检测蓝牙设备
我正在做一个iPhone应用程序,我需要得到附近的蓝牙设备。 我使用的是CoreBluetooth框架,但不起作用。我知道这个框架只适用于低能耗的蓝牙,所以我买了一个支持低能耗的蓝牙4.0USB适配器。我正在iPhone 5上测试这个应用程序。这是我的密码Iphone检测蓝牙设备,iphone,ios,detection,core-bluetooth,bluetooth-lowenergy,Iphone,Ios,Detection,Core Bluetooth,Bluetooth Lowenergy,我正在做一个iPhone应用程序,我需要得到附近的蓝牙设备。 我使用的是CoreBluetooth框架,但不起作用。我知道这个框架只适用于低能耗的蓝牙,所以我买了一个支持低能耗的蓝牙4.0USB适配器。我正在iPhone 5上测试这个应用程序。这是我的密码 - (void)centralManagerDidUpdateState:(CBCentralManager *)central{ NSString *messtoshow; switch (central.state) { ca
- (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."];
[mgr scanForPeripheralsWithServices:[NSArray arrayWithObject:[CBUUID UUIDWithString:@"180A"]] options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey]];
[mgr retrieveConnectedPeripherals];
break;
}
}
NSLog(messtoshow);
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:
(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"Did discover peripheral. peripheral: %@ rssi: %@, UUID: %@ advertisementData: %@ ", peripheral, RSSI, peripheral.UUID, advertisementData);
[mgr retrievePeripherals:[NSArray arrayWithObject:(id)peripheral.UUID]];
}
-(void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals{
NSLog(@"This is it!");
}
此打印“Bluetooth当前已通电并可用”,但找不到我的usb Bluetooth或附近的任何其他Bluetooth设备。我需要一个解决办法,我快疯了。
多谢各位 您确定180A是正确的服务吗 如果没有,请尝试:
[mgr scanForPeripheralsWithServices:nil options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey]];
你的代码看起来不错
如果他们的应用程序无法发现您的蓝牙设备,请确保您的蓝牙设备已打开并且正在进行广告宣传。我已尝试了所有posibles服务,并尝试将服务设置为零。它不起作用。我放弃了,但谢谢你。你检查过这个吗:?我最后遇到了类似的问题。你找到解决办法了吗?