unable to connect bluetooth device in ios 8 even e

2019-08-09 02:21发布

problem to connect Bluetooth device like wristband in ios 8 even existing code not finding Bluetooth and main thing it working very fine on ios 7..my code is as suggest me any idea or changes in ios 8 for Bluetooth..

-(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; 
 } 

1条回答
等我变得足够好
2楼-- · 2019-08-09 03:06

Your problem is that you are invoking scanForPeripheralsWithServices immediately after creating the CBCentralManager rather than waiting until the central manager is in the powered on state as indicated in the centralManagerDidUpdateState delegate.

- (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];
     }
}

in iOS 7 starting the scan before the power on state was indicated issued a warning on the console. In iOS 8 it doesn't start the scan.

查看更多
登录 后发表回答