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

来源:互联网 发布:国产动画 知乎 编辑:程序博客网 时间:2024/06/11 05:32

经过整个下午的调试,总算清楚何时会触发    - (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:}发起的连接没有完成,就会调用。

 

2 0
原创粉丝点击