iOS6:CBPeripheral在连接时被解除分配 [英] iOS6: CBPeripheral is being dealloc'ed while connecting

查看:169
本文介绍了iOS6:CBPeripheral在连接时被解除分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接蓝牙BTLE设备。我发现外围设备没有问题。

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:3​​6.110 CoreBluetooth [警告] 7DA9E322-D710-081B-4A9D-526DE546B13C,Name =Find My Car Smarter,IsConnected = NO> is在连接时被解除分配

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.

推荐答案

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

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;

然后在从<$ c返回之前,在发现设备时将外围设备分配给此属性$ c> 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;
}

这篇关于iOS6:CBPeripheral在连接时被解除分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆