gpt4 book ai didi

iOS8 和 BTLE | CBCentralManager 无法找到外围设备

转载 作者:技术小花猫 更新时间:2023-10-29 11:15:00 24 4
gpt4 key购买 nike

我有一个使用 BTLE 连接到设备 (arduino) 的 iOS 应用程序。在我的 iPad iOS 7 上一切正常。升级到 iOS 8 后,CBCentralManager 找不到任何外围设备。

- (void)startScanningForSupportedUUIDs
{
[self.centralManager scanForPeripheralsWithServices:nil options:nil];

}

我不知道可能是什么问题。

最佳答案

我有解决方案,由于某些原因,在 iOS 8 中实例化 CBManager 后会有一些延迟。需要在CBCentralManager开启时开始扫描,在这个方法中:

-(void)centralManagerDidUpdateState:(CBCentralManager *)central{
switch (central.state) {
case CBCentralManagerStatePoweredOff:
NSLog(@"CoreBluetooth BLE hardware is powered off");
break;
case CBCentralManagerStatePoweredOn:
{
NSLog(@"CoreBluetooth BLE hardware is powered on and ready");
NSArray *uuidArray = [NSArray arrayWithObjects:[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID], nil];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
[centralManager scanForPeripheralsWithServices:uuidArray options:options];
}
break;
case CBCentralManagerStateResetting:
NSLog(@"CoreBluetooth BLE hardware is resetting");
break;
case CBCentralManagerStateUnauthorized:
NSLog(@"CoreBluetooth BLE state is unauthorized");
break;
case CBCentralManagerStateUnknown:
NSLog(@"CoreBluetooth BLE state is unknown");
break;
case CBCentralManagerStateUnsupported:
NSLog(@"CoreBluetooth BLE hardware is unsupported on this platform");
break;
default:
break;
}

关于iOS8 和 BTLE | CBCentralManager 无法找到外围设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25389358/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com