unable to connect bluetooth device in ios 8 even existing code not finding bluetooth and main thing it woring very fine on ios 7

我怕爱的太早我们不能终老 提交于 2019-12-11 09:45:49

问题


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.



来源:https://stackoverflow.com/questions/26074216/unable-to-connect-bluetooth-device-in-ios-8-even-existing-code-not-finding-bluet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!