ios - 飞行模式切换时,CoreBluetooth 不会调用 didDisconnectPeripheral

标签 ios core-bluetooth bluetooth-lowenergy

我有一个 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/

相关文章:

javascript - 如何从 html/javascript 调用 MainViewController.h 方法? (IOS 手机间隙)

ios - 在 MapView 上渲染多条折线

ios - 当 BLE 设备不再可见时处理

android - BLE(低功耗蓝牙)配对和绑定(bind)

ios - 如何在 iOS 11.4 的 Xamarin Forms 中为编辑器/条目自动大写文本

objective-c - 在 cocos2d 游戏中,如何允许两个操纵杆同时输入?

iOS 在后台模式下省略广告中的制造商数据

bluetooth - Apple Watch Series 2 中的 CoreBluetooth

android - 如何获得蓝牙低功耗设备的 RSSI 值?

arduino - 如何在 Arduino Uno 上为 HM-10 BLE 设置服务和特性?