Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreBluetooth -- Discovery of BLE peripheral while device locked

I've noticed, that the discovery of a BLE peripheral seems to behave different (on the central-side) when the device is in the background compared to when it's in the background + locked.

Can someone confirm this or point me to more information/documentation?


To be more specific -- when my app (central) is transitioning into the background and to the home-screen, it continues to discover peripherals as intended, but when I press the Sleep/Wake-button and thereby lock the device, it stops discovering my peripherals. The app is not crashing or anything... in fact, when I unlock the device (back to the home-screen), it resumes discovering peripherals without a need to bring it back to the foreground. I also understand, that BLE is triggered less frequently when in the background, but in my case I watched it in locked state for well over an hour and it never triggered a discovery, but once I unlock it's back to normal.

I am looking for a solution, where I also am able to discover a peripheral, when the device (running as central) is locked.

Thanks for your help!

-H

Update...

Found an interesting post and thought I'd share: http://web.archiveorange.com/archive/v/lBeBkjSSTe5jAan6ufTX

Especially the observations (by Brian Fudge) are interesting...

  • A scanning device that is locked does not report any iOS peripherals that are also locked.

  • On some devices, like iPhone 5 and 5S, you only need to press the home button on the peripheral for the scanner to succeed and peripherals to be reported.

  • On other devices, like iPad and iPod Touch, you have to press the home button and unlock the peripheral for the scanner to succeed and peripherals to be reported.

  • A non-iOS device, such as an rMBP, can scan iOS peripherals that are in the background and locked.

  • All iOS devices can scan hardware peripherals (such as a health tracker) while the iOS device is in the background and locked.

like image 302
hschmied Avatar asked Oct 21 '22 17:10

hschmied


1 Answers

Ok i got the same problem and manage to understand why. So basically when you are in background or with the device locked, your app will be able to discover a device only one time (you can get multiple discovery in the foreground with the flag CBCentralManagerScanOptionAllowDuplicatesKey, but it's ignore in background)

So my app discovered without problems any BLE peripherals when it was in background but as soon as i locked my device i was unable to detect them. I figured out that the peripheral's broadcast packet is too huge (it was send in 2 times). Reducing my peripheral broadcast packet seems to fix the problem. When locked, the iPhone seems to listen to advertisement packet sent in one time. In foreground or background it is able to listen to packets send in 2 times.

Hope this can help someone.

like image 179
M to the K Avatar answered Oct 24 '22 03:10

M to the K