CoreBluetooth藍芽掃描協議問題
ios藍芽協議比較簡單,實現一些常用的功能只需要呼叫相對的方法就會觸發相應的協議,不過在ios8中呼叫掃描方法卻無法觸發相對應的協議,不知道為什麼?
解決方法如下:
//開始掃瞄
-(void)scanForPer{
if (!TARGET_IPHONE_SIMULATOR) {
NSDictionary *options = [NSDictionary
dictionaryWithObject:[NSNumber numberWithBool:NO]
forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
//ServicesUUIDs
[self.centralManager scanForPeripheralsWithServices:ServicesUUIDs options:options];
}
}
需要在此協議中再次呼叫一次才會執行
#pragma mark - ====== centralManager methods and delegate ======
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
switch (central.state) {//藍芽狀態的改變
case CBCentralManagerStatePoweredOn:{
[self scanForPer];
}
break;
default:
break;
}
}