objective c - iOS6: CBPeripheral is being dealloc'ed while connecting -
i'm trying connect bluetooth btle device. have no problem discovering peripheral.
however, when attempt connect peripheral, received following warning.
2013-04-05 22:10:36.110 corebluetooth[warning] 7da9e322-d710-081b-4a9d-526de546b13c, name = "find car smarter", isconnected = no> being dealloc'ed while connecting
furthermore, neither of relevant delegate methods called:
didconnectperipheral: didfailtoconnectperipheral: i've been struggling hours... please help.
short answer: need retain peripheral.
long explanation: core bluetooth not know whether interested in peripheral when discovered. connecting not enough, need retain it.
add property class doing that:
@property (strong) cbperipheral *connectingperipheral; and assign peripheral property when device discovered, before return 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; }
Comments
Post a Comment