9

好吧,我有一個應用程序掃描並連接到ios 6.0.1下的'bluetooth le'設備,但是在iphone 4s上,它運行良好。 應用程序上傳到蘋果商店時,他們回到我的應用程序崩潰,蝙蝠編程,但我只知道飛機墜毀時,我嘗試了iPhone5的應用,其中CBperipheral uuid在ios 6.0.1 i-phone5上是空的

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI; 

返回我的外圍與空UUID 。

我打印外設,名稱,uuid,rssi和advertData,一切都很好,但uuid爲空,我在應用程序中使用uuid。這使我的應用程序崩潰,我可以控制null uuid,這意味着我無法控制應用程序。

有人知道會發生什麼,並有可能的解決方案?

+0

接下來是可能的解決方案。 – Manelonix

+0

我找到了解決方案,在讀取服務後詢問uuid。只有當連接建立時,你可以知道和諮詢設備的uuid ......很快見到 – Manelonix

+0

我有代碼使用這個回調,當在iPad上運行時,我得到一個非bil periferial.UUI,但它是null在iPhone 6.0.1上 –

回答

2

我們要做的是下一個: 你不能用NSLog編寫外圍對象,但是我們在執行連接之前不能擁有外設的uuid屬性。它始終是空的。 我們要求uuid在讀取服務完成後,而不是之前,然後我們不能在沒有崩潰的情況下運行i-phone5上的應用程序。

我在TI(德州儀器)上看到它是一個ios錯誤,但是它是一個可靠的安全更新,在詢問uuid之前我們需要連接。

1

第一次連接後,設備會記住/緩存UUID。如果稍後發現相同的外設,則在連接之前,UUID將可用。您可以通過調用「retrievePeripherals」來請求所有記憶的外圍設備。

0

它似乎是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上看到它被調用過兩次),並且第二次完成了外圍設備的詳細信息。