我正在構建幾個BLE應用程序,並且遇到了我的BLE協議以及外部供應商的這個問題。在大多數情況下,BLE按預期工作,但有時它將無法發現針對特定外設的服務,並且在我重新啓動或重置手機之前不會再工作。xcode 5 CoreBluetooth未發現外圍設備的服務
有其他人遇到過這個問題嗎?
當我完成我的外圍設備時,經理將調用closePeripheralConnection
方法。相關代碼:
// Disconnect from peripheral
- (void)closePeripheralConnection
{
NSLog(@"== closePeripheralConnection ==");
// If the peripheral is connected
if (self.peripheral.state == CBPeripheralStateConnected && self.peripheral != nil) {
// Cancel connection
[self.manager cancelPeripheralConnection:self.peripheral];
} else {
[self clearPeripheralSettings];
}
}
// Clear peripheral settings
- (void)clearPeripheralSettings
{
// Clear peripheral variables
self.peripheral = 0;
// Clear services
self.service = 0;
// Clear characteristic values
self.data = 0;
self.notifyCharacteristic = 0;
}
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
{
[self clearPeripheralSettings];
}
請描述你的使用場景。但是,iOS BLE堆棧很容易陷入「僵局」並完全停止工作。 – allprog
@allprog在我開發時,我經常連接/斷開我的外設。外圍設備包含在用戶從外設發起連接時向其提供的數據。經理(我應用程序的一個視圖中的一個對象)將保持與外設的會話,直到接收完數據。此時,我取消了連接並執行了小的清理。請查看我最新的問題,瞭解經理如何推倒會議。 – abriggs
@abriggs:你有解決上述問題的方法嗎? –