我希望能够持续扫描蓝牙设备,并使应用程序在后台保持活动状态。这可能吗?如果我有一个连接的蓝牙设备,并且存在数据传输,则应用程序会在后台保持唤醒状态。但是,如果我只是在后台进行扫描,即使我已选中使用蓝牙LE配件
(在plist中为bluetooth-central
),应用程序最终也会停止运行。
有没有办法在后台保持应用程序持续扫描设备并保持其活动状态?
我希望能够持续扫描蓝牙设备,并使应用程序在后台保持活动状态。这可能吗?如果我有一个连接的蓝牙设备,并且存在数据传输,则应用程序会在后台保持唤醒状态。但是,如果我只是在后台进行扫描,即使我已选中使用蓝牙LE配件
(在plist中为bluetooth-central
),应用程序最终也会停止运行。
有没有办法在后台保持应用程序持续扫描设备并保持其活动状态?
我能在我的应用程序在后台运行时使用iOS设备发出iBeacon广告吗? 答案:不行。要想让iOS设备发出iBeacon广告,请求此功能的应用程序必须处于前台,屏幕已开启并且设备已解锁。
参考 - https://developer.apple.com/ibeacon/Getting-Started-with-iBeacon.pdf
我找到了这篇文章,它提供了一些在特定情况下连接后台BLE的详细信息。 https://medium.com/@cbartel/ios-scan-and-connect-to-a-ble-peripheral-in-the-background-731f960d520d
CBCentralManager
中:
/**
* @method scanForPeripheralsWithServices:options:
*
* @param serviceUUIDs A list of <code>CBUUID</code> objects representing the service(s) to scan for.
* @param options An optional dictionary specifying options for the scan.
*
* @discussion Starts scanning for peripherals that are advertising any of the services listed in <i>serviceUUIDs</i>. Although strongly discouraged,
* if <i>serviceUUIDs</i> is <i>nil</i> all discovered peripherals will be returned. If the central is already scanning with different
* <i>serviceUUIDs</i> or <i>options</i>, the provided parameters will replace them.
* Applications that have specified the <code>bluetooth-central</code> background mode are allowed to scan while backgrounded, with two
* caveats: the scan must specify one or more service types in <i>serviceUUIDs</i>, and the <code>CBCentralManagerScanOptionAllowDuplicatesKey</code>
* scan option will be ignored.
*
* @see centralManager:didDiscoverPeripheral:advertisementData:RSSI:
* @seealso CBCentralManagerScanOptionAllowDuplicatesKey
* @seealso CBCentralManagerScanOptionSolicitedServiceUUIDsKey
*
*/
open func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?, options: [String : Any]? = nil)