我正在尝试连接蓝牙 BTLE 设备。我可以毫无问题地发现外围设备。
但是,当我尝试连接到外围设备时,我收到了以下警告。
2013-04-05 22:10:36.110 CoreBluetooth[WARNING] 7DA9E322-D710-081B-4A9D-526DE546B13C, Name = "Find My Car Smarter", IsConnected = NO> is being dealloc'ed while connecting
此外,相关委托(delegate)方法均未被调用:
didConnectPeripheral:
didFailToConnectPeripheral:
我已经为此苦苦挣扎了几个小时...... 请帮忙。
最佳答案
简答:您需要保留外围设备。
详细解释:Core Bluetooth在被发现的时候并不知道你是否对这个外设感兴趣。连接到它是不够的,您需要保留它。
向您正在执行所有操作的类添加一个属性:
@property (strong) CBPeripheral *connectingPeripheral;
然后在发现设备时将外围设备分配给此属性,然后再从 didDiscoverPeripheral
返回:
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
DDLogVerbose(@"Discovered peripheral: %@ advertisement %@ RSSI: %@", [peripheral description], [advertisementData description], [RSSI description]);
[central connectPeripheral:peripheral options:nil];
self.connectingPeripheral = peripheral;
}
关于objective-c - iOS6:CBPeripheral 在连接时被释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15846663/