iOS之蓝牙开发—何时触发(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral方法

经过整个下午的调试,总算清楚何时会触发    - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error    方法。



当调用手机连接外设的方法: - (void)connectPeripheral:(CBPeripheral *)peripheral options:(nullable NSDictionary<NSString *, id> *)options;作为中心设备的手机会和硬件之间建立连接,但是建立连接也是需要一定时间的,具体的时间是多少我并没有测算出来,肯定是很短暂的,但也不是微乎其微。

就在这短暂的时间内,如果调用手机和外设断开的代理方法: - (void)cancelPeripheralConnection:(CBPeripheral *)peripheral;    那么就会进入连接失败的代理方法之中: - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error;  



/*!

 *  @method centralManager:didFailToConnectPeripheral:error:

 *

 *  @param central      The central manager providing this information.

 *  @param peripheral   The <code>CBPeripheral</code> that has failed to connect.

 *  @param error        The cause of the failure.

 *

 *  @discussion         This method is invoked when a connection initiated by {@link connectPeripheral:options:} has failed to complete. As connection attempts do not

 *                      timeout, the failure of a connection is atypical and usually indicative of a transient issue.

 *

 */

苹果官方给出的解释是由{@link connectPeripheral:options:}发起的连接没有完成,就会调用。

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值