iOS蓝牙背景模式

dz6r00yl  于 12个月前  发布在  iOS
关注(0)|答案(2)|浏览(129)

我希望继续扫描蓝牙设备,我希望应用程序在后台处于活动状态。这可能吗?看起来如果我有连接的蓝牙设备,如果有数据传输,那么应用程序在后台保持清醒。但是,如果我只是在后台扫描,似乎即使我检查了Uses Bluetooth LE accessories(plist中的bluetooth-central),应用程序最终也不会运行。
有没有办法让应用程序在后台运行时保持活跃并持续扫描设备?

2jcobegt

2jcobegt1#

根据苹果开发者文档技术问答。

**我的应用程序在后台运行时,我可以使用iOS设备发布iBeacon广告吗?**答:不可以。对于要发布iBeacon广告的iOS设备,请求此功能的应用程序必须位于最前面,屏幕已打开且设备已解锁。

参考-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

ldioqlga

ldioqlga2#

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)

字符串
这里重要的是Applications that have specified the bluetooth-central background mode are allowed to scan while backgrounded, with two caveats (...)
@huggie,你有什么成就吗?

相关问题