iOS蓝牙后台模式

13

我希望能够持续扫描蓝牙设备,并使应用程序在后台保持活动状态。这可能吗?如果我有一个连接的蓝牙设备,并且存在数据传输,则应用程序会在后台保持唤醒状态。但是,如果我只是在后台进行扫描,即使我已选中使用蓝牙LE配件(在plist中为bluetooth-central),应用程序最终也会停止运行。

有没有办法在后台保持应用程序持续扫描设备并保持其活动状态?

2个回答

2
根据苹果开发者文档中的技术问答,以下是翻译:

我能在我的应用程序在后台运行时使用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


1
另一篇信息丰富的文章是Leveraging Background Bluetooth for a Great User Experience - Ed of the Mountain

1
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)

这里的重点是,已经指定了蓝牙中央后台模式的应用程序可以在后台进行扫描,但有两个注意事项(...)。
@huggie,你有什么成果吗?

这已经是8年前的事了,我记不清了,但还是谢谢你的回答! - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接