简体   繁体   English

在iOS中在后台实施BLE扫描

[英]Implement BLE scan in the background in iOS

I have a query regarding Scanning of the BLE devices in an iOS app. 我有一个有关在iOS应用程序中扫描BLE设备的查询。

Use case of our app is to share the location of a set of BLE devices assigned to each user continuously to a particular server for every 15 minutes time interval, irrespective of the state of the app (except terminated state may be). 我们的应用程序的用例是,每隔15分钟时间间隔,将与分配给每个用户的一组BLE设备的位置连续共享给特定的服务器,而不管该应用程序的状态如何(终止状态除外)。

About our BLE device, it transmits the advertisement data once for every 4 second interval. 关于我们的BLE设备,它每隔4秒发送一次广告数据。

We tried using the "uses Bluetooth LE accessory" background mode and continuously we were able to scan the BLE devices using the scanForPeripharal method in CBCentralManager with the UUIDs of the BLE devices. 我们尝试使用“使用Bluetooth LE附件”背景模式,并且连续不断地能够使用BLE设备的UUID在CBCentralManager中使用scanForPeripharal方法扫描BLE设备。

We were able to get the list of scanned devices even in the background. 即使在后台,我们也可以获取扫描设备的列表。 But when we lock the device and the screen becomes inactive/turned off, we are unable to get the list of scanned devices. 但是,当我们锁定设备并且屏幕变得不活动/关闭时,我们将无法获得扫描设备的列表。

In another solution, we tried using the background fetch but it is very inconsistent(practically it never gets called in the given time interval). 在另一种解决方案中,我们尝试使用后台提取,但是它非常不一致(实际上,在给定的时间间隔内永远不会调用它)。

We need a solution using which we should be able to do the following, For every 15 minutes time interval. 我们需要一种解决方案,使用该解决方案,每15分钟间隔应执行以下操作。 scan the BLE peripherals around our vicinity. 扫描我们附近的BLE外设。 Get the current location of the user. 获取用户的当前位置。 Share it with a MQTT server. 与MQTT服务器共享。

A couple of options: 有两个选择:

  1. If you have a custom BLE device anyway, you could modify it to send a stream of iBeacon advertisements periodically, say a burst of 10 packets every 15 minutes. 如果您仍然拥有定制的BLE设备,则可以对其进行修改以定期发送iBeacon广告流,例如每15分钟发送10个数据包。 An app looking for the iBeacon using CoreLocation would wake up in the background every 15 minutes and you could then read your other advertisements with CoreBluetooth . 一个使用CoreLocation查找iBeacon的应用程序每隔15分钟就会在后台唤醒一次,然后您可以使用CoreBluetooth阅读其他广告。

  2. You could make your app request location background modes, and request fine location updates. 您可以让您的应用请求位置背景模式,并请求精确的位置更新。 This may allow you to get BLE device discoveries after receiving callbacks for location update events. 这可能允许您在收到位置更新事件的回调后获得BLE设备发现。 The disadvantage is that you would need to satisfy the AppStore reviewers that your app is a consumer navigation app to get it in the AppStore. 缺点是您需要使AppStore审阅者确信您的应用程序是消费者导航应用程序,才能在AppStore中获得它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM