无法在ios 8中连接蓝牙设备,即使现有代码找不到蓝牙,主要问题是它在ios 7上运行得很好

无法在ios 8中连接蓝牙设备,即使现有代码找不到蓝牙,主要问题是它在ios 7上运行得很好,ios,bluetooth-lowenergy,Ios,Bluetooth Lowenergy,在ios 8中连接蓝牙设备(如腕带)时出现问题,即使现有代码没有找到蓝牙,主要问题是它在ios 7上工作得很好。我的代码如下 建议我ios 8中蓝牙的任何想法或更改 -(void)connecttodevice { // Scan for all available CoreBluetooth LE devices NSArray *services = @[[CBUUID UUIDWithString:info_UUID],[CBUUID UUIDWithString:

在ios 8中连接蓝牙设备(如腕带)时出现问题,即使现有代码没有找到蓝牙,主要问题是它在ios 7上工作得很好。我的代码如下 建议我ios 8中蓝牙的任何想法或更改

-(void)connecttodevice { 
     // Scan for all available CoreBluetooth LE devices 
     NSArray *services = @[[CBUUID UUIDWithString:info_UUID],[CBUUID UUIDWithString:info_UUID_service],[CBUUID UUIDWithString:BAND_SERVICE_INFO]]; 
     NSLog(@"device connting....."); 
     CBCentralManager *centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; 
     [centralManager scanForPeripheralsWithServices:services options:nil]; 
     self.centralManager = centralManager; 
 } 

您的问题是,您在创建CBCentralManager后立即调用scanForPeripheralsWithServices,而不是等到CentralManagerDipDateState委托中指示的中央管理器处于通电状态

- (void)centralManagerDidUpdateState:(CBCentralManager *)central

     if (central.state == CBCentrallManagerStatePoweredOn {
        NSArray *services = @[[CBUUID UUIDWithString:info_UUID],[CBUUID UUIDWithString:info_UUID_service],[CBUUID UUIDWithString:BAND_SERVICE_INFO]]; 
        NSLog(@"device connting....."); 
        [central scanForPeripheralsWithServices:services options:nil];
     }
}

在iOS 7中,在指示开机状态之前启动扫描会在控制台上发出警告。在iOS 8中,它不会启动扫描。

您的问题是,您在创建CBCentralManager后立即调用scanForPeripheralsWithServices,而不是等到CentralManager处于开机状态(如CentralManagerDipDateState委托所示)

- (void)centralManagerDidUpdateState:(CBCentralManager *)central

     if (central.state == CBCentrallManagerStatePoweredOn {
        NSArray *services = @[[CBUUID UUIDWithString:info_UUID],[CBUUID UUIDWithString:info_UUID_service],[CBUUID UUIDWithString:BAND_SERVICE_INFO]]; 
        NSLog(@"device connting....."); 
        [central scanForPeripheralsWithServices:services options:nil];
     }
}

在iOS 7中,在指示开机状态之前启动扫描会在控制台上发出警告。在iOS 8中,它不会启动扫描。

-voidconnecttodevice{//扫描所有可用的CoreBluetooth LE设备NSArray*服务=@[[CBUUID UUIDWithString:info\u UUID],[CBUUID UUIDWithString:info\u UUID\u service],[CBUUID UUIDWithString:BAND\u service\u info];NSLog@device连接….;CBCentralManager*centralManager=[[CBCentralManager alloc]initWithDelegate:self queue:nil];[centralManager ScanFor PeriphersWithServices:services options:nil];self.centralManager=centralManager;}-voidconnecttodevice{//扫描所有可用的CoreBluetooth设备NSArray*服务=@[[CBUUID UUID UUID WithString:info_UID],[CBUUID UUIDWithString:info_UUID_service],[CBUUID UUIDWithString:BAND_service_info];NSLog@device连接….;CBCentralManager*centralManager=[[CBCentralManager alloc]initWithDelegate:self-queue:nil];[centralManager扫描外围设备服务:服务选项:nil];self.centralManager=centralManager;}