iOS Question Periodic background Bluetooth connections

Alessandro71

Well-Known Member
Licensed User
Longtime User
I'm working on an app which needs to stay active while in background (i.e. not displayed on screen, while the user is doing something else, like talking on the phone or browsing the web) and performing periodic (every 5 minutes) connections to a BLE device.
So far, I'm using the following
B4X:
#PlistExtra: </array>
#PlistExtra: <key>UIBackgroundModes</key>
#PlistExtra: <array>
#PlistExtra:   <string>bluetooth-central</string>
#PlistExtra:   <string>processing</string>
#PlistExtra:   <string>fetch</string>
#PlistExtra: </array>
trying to prevent the OS from killing the app, but it seems to remain alive just for a few minutes and then it gets killed.
Anyone with similar experiences?
 

JordiCP

Expert
Licensed User
Longtime User
I think it's not possible to do precise timely scheduled tasks in the background with iOS
With location and the appropiate background bluetooth usage declarations in plist, if you make sure to leave the ble scanning for certain services when going to background, this task is transfered to coreBluetooth and your app will be awakened (even if it has been system-killed, not user-killed) when a bluetooth peripheral matching the searched serviceId is found.
With this, you can keep track of the last time you connected to it and, if 5 minutes or more have passed, since previous connection, connect again, remembering to always leave the scan active when finished.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
your app will be awakened (even if it has been system-killed, not user-killed) when a bluetooth peripheral matching the searched serviceId is found.
I need to perform some tests on that, because, possibly, the peripheral will always be in range
 
Upvote 0
Top