【发布时间】:2019-09-06 15:24:45
【问题描述】:
我已经构建了一个 iOS 应用,它使用蓝牙低功耗 (BLE) 与设备交换数据,这是一个核心蓝牙框架。
当应用程序处于后台时,即使设备已向 iPhone 发送数据,BLE 框架也不会将此数据发送到应用程序。
当应用程序进入前台时,它会接收应用程序在后台时发送的所有数据。这意味着 iPhone 的蓝牙层接收到数据,但它只是存储数据并在应用程序进入前台时交付给应用程序。
这并不总是问题。这是随机发生的。
// application went to background
2019/04/13 11:54:38:174 BLEManager# applicationDidEnterBackground
2019/04/13 11:54:38:176 BLEBackgroundTaskManager# applicationDidEnterBackground
// application receives data when it comes to foreground although this data was sent from device at 11:54:40:256
2019/04/13 12:39:36:149 CentralManager# Value received is <02>
预期的结果是didUpdateValueForCharacteristic 将在接收到数据时被调用,但当应用程序处于后台时不会调用此 API。当应用进入前台时会调用此 API。
【问题讨论】:
标签: ios background bluetooth-lowenergy core-bluetooth data-transfer