Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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? 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.

Appreciate the help,

Casey

like image 327
CaseyG Avatar asked Dec 29 '12 18:12

CaseyG


People also ask

What is Bluetooth peripheral mode?

Device modes Peripheral mode lets devices send advertisement packets. Central mode lets devices scan for advertisements. An Android device acting as both a peripheral and central device can communicate with other BLE peripheral devices while sending advertisements in peripheral mode.

Can an iPhone be a BLE peripheral?

The code-based examples that follow will assist you in developing your app to implement the peripheral role on your local device. So: yes, it's possible. There are probably apps that make your iPhone act like a peripheral, since the ability has been supported since iOS 6.0.

What is core Bluetooth?

The Core Bluetooth framework provides the classes needed for your apps to communicate with Bluetooth-equipped low energy (LE) and Basic Rate / Enhanced Data Rate (BR/EDR) wireless technology. Don't subclass any of the classes of the Core Bluetooth framework.

How do I enable BLE on my iPhone?

On your iOS device go into "Settings-> Bluetooth" and turn on your BLE device. You should see the device listed in your available devices.


1 Answers

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. To speed it up I programmed the peripheral to advertise every 20ms for the first 30s.

Also you must define "Requires background mode" with "App communicates using CoreBluetooth" in your project Targets -> Info.

It does take a while for the app to find peripherals in the background mode.

like image 75
henrik Avatar answered Sep 21 '22 08:09

henrik