我正在构建几个 BLE 应用程序,并且在我的 BLE 协议以及外部供应商中遇到了这个问题。在大多数情况下,BLE 会按预期工作,但有时它会无法发现特定外围设备的服务,并且在我重新启动或重置手机之前不会再次工作。
有没有其他人遇到过这个问题?
当我用完外围设备后,经理将调用该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];
}