unable to connect bluetooth device in ios 8 even e

2019-08-09 02:27发布

问题:

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:

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.