在 IOS 应用程序中,当应用程序处于终止状态时,如何继续扫描 BLE 传感器。当应用程序运行时,我可以管理多个传感器。但是,当App终止后,如何继续收听广告并将Sensor连接到App未运行状态。
状态保存和状态恢复已实现。后台模式蓝牙中心已开启
我想像 Tile 和 Chipolo 在终止状态下那样实现它。
最佳答案
普通 ble 功能无法实现您想要实现的目标:
Apps that support background execution may be relaunched by the system to handle incoming events. If an app is terminated for any reason other than the user force quitting it, the system launches the app when one of the following events happens:
引用Understanding When Your App Gets Launched into the Background
tile 的工作方式是使用 iBeacon 标准(我的最佳猜测)。
iBeacon 本质上是一个 BLE。您的应用程序可以启动 Region Monitoring for an iBeacon接收区域事件(进入、退出)。如果用户杀死了您的应用程序,这些事件也会唤醒您的应用程序。当您的应用程序被区域输入事件唤醒时,您有 8 秒(或多或少)来执行代码并对事件使用react。在此时间内,您可以启动标准 BLE 连接以使用 iBeacon 作为外围设备,并使您的应用程序对 BLE 事件使用react。
当然,您的外设必须设计为支持此类行为。
关于ios - 如何在 iOS 应用程序终止时继续扫描 BLE 传感器并识别传感器 keyEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48236884/