我有一个 CoreBluetooth
应用程序。这会在前台启动连接并开始发送/接收数据,并在发送到后台时继续执行此操作,因为我已将 bluetooth-central
添加到 app-Info 中的
。 UIBackgroundModes
。 plist
如果我切换飞行模式设置,我的应用会断开连接,但它不会获得 didDisconnectPeripheral
回调。为什么是这样?
我的解决方法是清除 centralManagerDidUpdateState
中对我的 CBPeriperal
对象的所有引用,以便能够在应用程序再次进入前台时进行新的扫描和连接.
最佳答案
与您的其他问题的答案相同 -> App don't discover services when reconnecting after power cycling bluetooth
当您的 centralManager 更新为 CBCentralManagerStatePoweredOff
时,您需要在所有外围设备上调用 cancelConnection:
关于ios - 飞行模式切换时,CoreBluetooth 不会调用 didDisconnectPeripheral,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17964568/