简体   繁体   English

使用Core Bluetooth在后台获取蓝牙LE外围设备广告

[英]Using Core Bluetooth to get Bluetooth LE peripheral advertisements in background

I'm having trouble figuring out how to receive Bluetooth LE peripheral device advertisements while my app is running in the background. 我的应用程序在后台运行时,我无法弄清楚如何接收蓝牙LE外围设备广告。 That is, when my app is in the background it never reaches the didDiscoverPeripheral() method--where the advertisement lies.. Does anyone know how I need to configure my app such that I can get Bluetooth LE advertisements while my app is in the background? 也就是说,当我的应用程序在后台时,它永远不会到达didDiscoverPeripheral()方法 - 广告所在的位置..有没有人知道我需要如何配置我的应用程序,这样我可以获得蓝牙LE广告,而我的应用程序在背景? Can this be done with a thread polling while my app is in the background? 当我的应用程序在后台时,可以通过线程轮询来完成吗? Note: I want to get advertisements from all BLE devices, not a defined number of BLE devices. 注意:我想从所有BLE设备获取广告,而不是定义数量的BLE设备。

Appreciate the help, 感谢帮助,

Casey 卡西

I am doing this from my app. 我是从我的应用程序这样做的。

in background mode CoreBluetooth is said to be up to 55 times slower than the advertisement interval of the peripheral. 在后台模式下,CoreBluetooth据说比外围设备的广告间隔慢55倍。 To speed it up I programmed the peripheral to advertise every 20ms for the first 30s. 为了加快速度,我编程了外设,在前30秒内每20ms做一次广告。

Also you must define "Requires background mode" with "App communicates using CoreBluetooth" in your project Targets -> Info. 此外,您必须在项目目标 - >信息中使用“使用CoreBluetooth进行应用程序通信”定义“需要后台模式”。

It does take a while for the app to find peripherals in the background mode. 应用程序需要一段时间才能在后台模式中查找外围设备。

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

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