ios - 如何在 iOS 应用程序终止时继续扫描 BLE 传感器并识别传感器 keyEvent

标签 ios swift bluetooth-lowenergy

在 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/

相关文章:

ios - 在 UIView 中移动和缩放 UIImageView

swift - 为什么 Swift 不允许在 class init 中给 self 赋值,而在 protocol init 中却不允许?

swift - 使用 React native 框架的 Eddystone 信标扫描

ios - 在 ios 中将变量分配给 NSDictionary 的值?

ios - uicollectionviewcell swift ios 中的自定义复选框

ios - 如何在数据快照中提取节点的子节点

葡萄糖的 Android BLE 通知

ios - 如果我知道 iOS 中该 BLE 设备的 mac 地址,如何区分我应该连接哪个 BLE 设备的外围设备?

ios - 如何将 objective-c 函数作为回调传递给 C 函数?

ios - 如何读取 Firebase 快照并将特定的键值对存储在通用数组中?