美文网首页
iOS之蓝牙开发—何时触发(CBCentralManager *

iOS之蓝牙开发—何时触发(CBCentralManager *

作者: Moker_C | 来源:发表于2018-10-13 14:27 被阅读17次

当调用手机连接外设的方法:

- (void)connectPeripheral:(CBPeripheral *)peripheral options:(nullable NSDictionary<NSString *, id> *)options;

作为中心设备的手机会和硬件之间建立连接,建立连接需要一定时间,具体的时间未知,肯定是很短暂的,但也不是微乎其微。

就在这短暂的时间内,如果调用手机和外设断开的代理方法:

 - (void)cancelPeripheralConnection:(CBPeripheral *)peripheral;

那么就会进入连接失败的代理方法之中:

- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error;

苹果API的解释:当{@link connectPeripheral:options:}启动的连接无法完成时,将调用此方法。 由于连接尝试(不会超时),因此连接失败是非典型的,通常表示存在暂时性问题

*  @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.

相关文章

网友评论

      本文标题:iOS之蓝牙开发—何时触发(CBCentralManager *

      本文链接:https://www.haomeiwen.com/subject/eneoaftx.html