尝试重新连接配对的蓝牙设备

时间:2012-08-09 07:12:44

标签: ios bluetooth

我正试图在CBCentralManager的帮助下使用以下方法配对蓝牙设备。

- (void)connectPeripheral:(CBPeripheral *)peripheral options:(NSDictionary *)options;

我在选项词典中将CBConnectPeripheralOptionNotifyOnDisconnectionKey传递给了true。

它第一次工作并弹出,询问确认配对来和设备连接。我怎么用

断开此设备
- (void)cancelPeripheralConnection:(CBPeripheral *)peripheral;

或设备超出范围然后当我尝试使用相同的"connectPeripheral: options:"方法连接相同的设备时,它没有连接。我在这里做错了什么。

1 个答案:

答案 0 :(得分:0)

检查您的代理功能 didDisconnectPeripheral ,您可能错过了设置或重置标记。

来自CoreBluetooth: Heart Rate Monitor的示例代码。

/*
 Invoked whenever an existing connection with the peripheral is torn down. 
 Reset local variables
 */
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)aPeripheral error:(NSError *)error
{
    self.connected = @"Not connected";
    [connectButton setTitle:@"Connect"];
    self.manufacturer = @"";

    if( peripheral )
    {
        [peripheral setDelegate:nil];
        [peripheral release];
        peripheral = nil;
    }
}
相关问题