13

I'm trying to connect to a bluetooth BTLE device. I have no problem discovering the peripheral.

However, when I attempt to connect to the peripheral, I received the following warning.

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

Furthermore, neither of the relevant delegate methods are called:

didConnectPeripheral:
didFailToConnectPeripheral:

I've been struggling with this for hours... Please help.

4

1 回答 1

37

简短回答:您需要保留外围设备。

长解释:酷睿蓝牙被发现时不知道你是否对这个外设感兴趣。连接到它是不够的,你需要保留它。

将属性添加到您正在执行所有这些操作的类中:

@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;
}
于 2013-04-07T13:31:14.503 回答