我正在寻找一种解决方案,以便在应用程序处于后台状态时通过iOS设备扫描BLE外围设备。我试过检查功能,在info.plist中为后台进程添加了中央和外围设备,创建了一个单例CBCentralManager。它在前台扫描并连接到BLE设备,但一旦转到后台,它就不会调用didDiscover方法。对于同样的问题有什么解决方案吗?提前谢谢。
我的info.plist
<array>
<string>bluetooth-central</string>
<string>bluetooth-peripheral</string>
<string>fetch</string>
<string>location</string>
<string>processing</string>
<string>remote-notification</string>
</array>我的能力

正如您所提到的,我还使用服务调用了scanPeripheral。
centralManager.scanForPeripherals(withServices: [CBUUID(string: "6T5FFJJIL-B5A3-D839-LDKL-KJBLKJ33")])我还尝试对scanPeripherals和retrievePeripherals委托的选项使用允许重复真/假。
发布于 2021-10-25 14:35:58
您几乎可以肯定会将nil作为scanForPeripherals的forServices参数进行传递。This is not allowed in the background.
您的应用程序可以通过指定蓝牙中央后台模式在后台扫描蓝牙设备。为此,您的应用程序必须通过在serviceUUIDs参数中指定服务来显式扫描一个或多个服务。在后台扫描时,CBCentralManager扫描选项不起作用。
https://stackoverflow.com/questions/69708518
复制相似问题