它似乎是iOS 6中的一個bug /功能增強,它使得它在iPhone 5上更加明顯,我認爲由於代碼的異步性質。我也有適用於4S的代碼,但不適用於5。
大多數人發佈的解決方法是確保您連接到找到的所有設備。解釋是直到建立連接才分配UUID。
你可以看到在TI傳感器標籤代碼的這個例子中,你可以從TI網站
-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
NSLog(@"Found a BLE Device : %@",peripheral);
/* iOS 6.0 bug workaround : connect to device before displaying UUID !
The reason for this is that the CFUUID .UUID property of CBPeripheral
here is null the first time an unkown (never connected before in any app)
peripheral is connected. So therefore we connect to all peripherals we find.
*/
peripheral.delegate = self;
[central connectPeripheral:peripheral options:nil];
[self.nDevices addObject:peripheral];
}
下載然而值得注意的是,你還可以做以下
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"didDiscoverPeripheral");
if (![foundPeripherals containsObject:peripheral]) {
NSLog(@"foundPeripherals addObject %@", peripheral.name);
[foundPeripherals addObject:peripheral];
} else {
NSInteger index = [foundPeripherals indexOfObject:peripheral];
NSLog(@"foundPeripherals replaceObject %@", peripheral.name);
[foundPeripherals replaceObjectAtIndex:index withObject:peripheral];
}
}
因爲didDiscoverPeripheral
每個設備都會被多次調用(我在iPhone 5上看到它被調用過兩次),並且第二次完成了外圍設備的詳細信息。
接下來是可能的解決方案。 – Manelonix
我找到了解決方案,在讀取服務後詢問uuid。只有當連接建立時,你可以知道和諮詢設備的uuid ......很快見到 – Manelonix
我有代碼使用這個回調,當在iPad上運行時,我得到一個非bil periferial.UUI,但它是null在iPhone 6.0.1上 –