iOS6: CBPeripheral is being dealloc'ed while connecting iOS6: CBPeripheral is being dealloc'ed while connecting objective-c objective-c

iOS6: CBPeripheral is being dealloc'ed while connecting


Short answer: You need to retain the peripheral.

Long explanation: Core Bluetooth does not know whether you are interested in this peripheral when it is discovered. Connecting to it is not enough, you need to retain it.

Add a property to the class where you are doing all that:

@property (strong) CBPeripheral     *connectingPeripheral;

And then assign the peripheral to this property when the device is discovered, before you return from 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;}