7

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

CaseyG
  • 115
  • 3
  • 6

1 Answers1

8

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.

henrik
  • 1,312
  • 9
  • 9
  • 1
    I appreciate your help. I'll try this out as soon as I get home and let you know if it works. To make sure you understand, your app will reach the didDiscoverPeripheral() method correct? In turn, allowing your app to parse the Peripherals advertisement.. – CaseyG Dec 30 '12 at 00:45
  • Hmm, I still have not been able to get it working. I switched my advertisement interval to 20ms like you noted. I think my problem may be that I'm using an unrestricted scan (ex: scanForPeripherals:nil options:options) and not a restricted scan. iOS may cancel unrestricted scans when your app goes into the background someone stated [here](http://stackoverflow.com/questions/9896562/what-exactly-can-corebluetooth-applications-do-whilst-in-the-background). Are you using an unrestricted scan or restricted? I would like to use an unrestricted for my app--if its possible. Thanks for your help. – CaseyG Dec 31 '12 at 22:47
  • Ok, I got it working. You must use a restricted scan and you must set your interval around 20ms like henrik mentioned. Thanks. – CaseyG Jan 16 '13 at 19:12
  • 2
    What do you guys mean by setting the interval? I can't find any functions that provide this functionality. Can you help? – Dave Leverton Feb 20 '13 at 10:47
  • @CaseyG If advertising is 20ms, roughly how soon will you get the advertising packets at the iOS side? In hundreds of milliseconds, or a few seconds or a few tens of seconds? Thanks. – foresightyj Apr 15 '13 at 02:09
  • 1
    Sorry, just noticed your guys comments (Dave/Foresightyj). You must set the BLE Peripheral device to advertise at 20ms intervals using its firmware. When the BLE Peripheral device is set to advertise at 20 ms intervals my app is able to pick up the advertisements in the Background in about 2-5 seconds. – CaseyG May 12 '13 at 18:43