【问题标题】:iOS CoreBluetooth reconnecting while app in backgroundiOS CoreBluetooth 在后台重新连接应用程序
【发布时间】:2013-06-27 23:36:04
【问题描述】:

我的问题是“一旦应用不在前台,我该如何重新连接到 ble 设备”?我已经完成了我的研究,似乎连接到配对 ble 设备的最佳方式是通过 retrivePeripherals:UUID。一旦找到某些东西,didRetivePeripherials 就会被回调,在这里我可以尝试再次重新连接到设备。当应用程序在后台运行时,我似乎无法执行此操作。

感谢您的帮助。

安德烈斯·N.

【问题讨论】:

    标签: ios background core-bluetooth cbcentralmanager


    【解决方案1】:
    1. 启用bluetooth-central后台模式
    2. 在实例化CBCentralManager 时使用CBCentralManagerOptionRestoreIdentifierKey 选项提供唯一标识符
    3. 实现- (void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionary *)state 委托方法
      3.1 使用NSArray *peripherals = state[CBCentralManagerRestoredStatePeripheralsKey]获取可恢复外设数组
      3.2 调用你的CBCentralManagerconnectPeripheral 方法提供每个外围设备进行恢复

    Core Bluetooth Programming Guide中阅读更多详细信息

    【讨论】:

    • 如果应用被用户强制关闭,将无法连接。
    猜你喜欢
    • 2015-05-02
    • 2013-07-21
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    • 2017-02-16
    • 2012-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多