I wish to keep scanning for Bluetooth Devices and I want app to be alive in the background. Is it possible? It seems like if I have a connected Bluetooth device, and if there is data transfer, then the app stays awake in the background. However, if I am just scanning in the background, it seems like even if I have Uses Bluetooth LE accessories
checked(bluetooth-central
in plist), the app ends up not running.
Is there a way to keep the app alive and continuous scan for devices when it is in the background?
The bluetooth-central Background Execution Mode plist file, the Core Bluetooth framework allows your app to run in the background to perform certain Bluetooth-related tasks. While your app is in the background you can still discover and connect to peripherals, and explore and interact with peripheral data.
iOS puts strict limits on background execution. Its default behaviour is to suspend your app shortly after the user has moved it to the background; this suspension prevents the process from running any code. There's no general-purpose mechanism for: Running code continuously in the background.
iOS restricts the use of background operations to improve user experience and extend battery life. Your app can run in the background for specific use cases, including: playing audio, updating location and fetching the latest content from a server.
The UIBackgroundModes key identifies which background tasks your application supports. Its value is an array that contains one or more strings with the following values: audio – The application plays audible content to the user while in the background.
As per apple developer documentation technical Q&A.
Can I use an iOS device to issue iBeacon advertisements while my app is in the background? Answer: No. For an iOS device to issue iBeacon advertisements, the app requesting this functionality must be frontmost, with the screen turned on and the device unlocked.
Reference - https://developer.apple.com/ibeacon/Getting-Started-with-iBeacon.pdf
I found this article which provides some details to connect BLE in background for some specific case. https://medium.com/@cbartel/ios-scan-and-connect-to-a-ble-peripheral-in-the-background-731f960d520d
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With