连接像ios 8中的腕带这样的蓝牙设备,甚至连现有的代码都找不到蓝牙,而且它在ios 7..my代码上工作得很好的主要问题,就像我建议我在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;
} 发布于 2014-09-27 12:01:38
您的问题是在创建scanForPeripheralsWithServices之后立即调用CBCentralManager,而不是像centralManagerDidUpdateState委托中指出的那样等待中央管理器处于开机状态。
- (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中,它不启动扫描。
https://stackoverflow.com/questions/26074216
复制相似问题