objective-c - iOS6:CBPeripheral 在连接时被释放

标签 objective-c ios6 core-bluetooth cbperipheral

我正在尝试连接蓝牙 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/

相关文章:

iphone - 在放置在 UIImageview 上的矩形框架中创建图像

ios - iPhone corebluetooth central Manager向外设发送数据

ios - CoreBluetooth 在预定时间在后台运行

objective-c - viewDidLoad 中的 CoreData performFetch 不起作用

ios - 要在 ios 中重用的 UITableViewCells 数组

iphone - 如何在 UIToolBar 中添加条形按钮

iphone - Storekit 框架可以在 iOS 6 模拟器上运行吗?

iphone - iPhone 4S 上的核心蓝牙故障?

objective-c - 使用 NSButton 打开 web URL - Mac OS

ios - 如何在 AVPlayerViewController 中添加完成按钮?