Launching iOS BLE Central application on iPhone reboot - ios

I am planning to develop an iOS application using CoreBluetooth framework which monitors a pedometer peripheral continuously and counts the footsteps.
I know that if backgroud execution mode is set to BLE Central, the application will continue to receive BLE events even in the background.
Apple documentation states that in case the app gets terminated due to low memory, the system can keep track of BLE events for a particular Central Manager if state preservation and restoration is adopted.
Assume I have an iOS application that operates in Central mode. The app is subscribed to receive notification from a Pedometer when ever the footstep characteristic changes.
I have adopted the following in my app.
BLE Central background mode
BLE State preservation/restoration for Central Manager
I start my app, Scan, Pair and Connect to the pedometer and the app starts receiving footsteps.
My Questions:
Now if the iPhone reboots, Will I continue to receive BLE events so that my app will be launched in the background without the user having to manually launch the application again and connect to the pedometer?
If the app is terminated by the user explicitly using the multitasking gesture, Will the app be able to receive BLE events without the user having to manually launch the application again and connect to the pedometer?
Is there a way to launch my application on iOS boot up?

Now if the iPhone reboots, Will I continue to receive BLE events so that my app will be launched in the background without the user having to manually launch the application again and connect to the pedometer?
Your app won't receive BLE events because all apps are started in the terminated state after a reboot (despite remaining in the app switcher). The user will have to manually launch your app at least once after reboot in order for it to use BLE.
If the app is terminated by the user explicitly using the multitasking gesture, Will the app be able to receive BLE events without the user having to manually launch the application again and connect to the pedometer?
Same as above, the app has entered the terminated state, so it won't be able to communicate using BLE until it is explicitly launched again.
Is there a way to launch my application on iOS boot up?
iOS doesn't provide any way to launch your application on boot.
The one exception to all of this that I can find is iBeacons. If your app registers to receive updates for a specific iBeacon, iOS will launch your app when it finds it (even after a reboot or if the user explicitly kills it from the switcher). When you get the iBeacon callback you can start all your BLE logic and it will then run in the background per usual. Of course this means you need to advertise as an iBeacon on your pedometer, which may or may not be feasible.
Bear in mind the detection of the iBeacon is pretty finicky, especially after a reboot. You have little guarantee as to how fast or even if you will be delivered the iBeacon callback to start your app. But it's something.
Source

Related

How Do i relaunch my iOS app from Kill state for long task?

First i will explain what i want to achieve.
I have a BLE lock. i want that my application will wake up from kill state and start scanning BLE device. Once the BLE device found it will connect with my phone and get unlock.
All this is working in background mode and i tested this many times. but i also want this to be work when app is in kill state.
I tried several things. First I tried Geofencing but in case of geofencing app wake up for less time i'm not properly scan the BLE device. When didEnterRegion region: called i sent the local notification and it was working fine. So after that i tried to scan BLE Devices when didEnterRegion region: and also get the notification that scan is started but i think after some time app remove from the background automatically and could not relaunch. So that's why i'm failed to discovered any BLE device.
I also read apple document for Core BlueTooth:
https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html
There is mention that how to perform long task like open and close door lock but isn't help me.
Please guide me how to do this when app is in kill state.
Thanks for the help :)
UPDATE:
What i mean from kill state is suspended/ terminated/removed from background. I just want that once user get enter into the region of geofence then app launch in background and scanning for the BLE device started. so after that i want app will stay into the background until door get unlock.
As Paulw11 mentioned, there's no way to relaunch an app in the background once it is terminated/killed by the user. Apple have done this deliberately for security and functionality reasons: if a user deliberately kills an app because it is buggy/faulty, the app should not be able to relaunch itself.
More information can be found here:-
Core Bluetooth Background Processing for iOS Apps
BLE device keep connect with iPhone when application terminate
I hope this helps.
did u try SLC. It wakes up the app after a kill. Then u can run a long running background task for BLE activity.

ios ble data lost after being killed in background mode

I have an iPhone app that receive BLE info from a particular device. The device sends data to my app anytime it has something to report, and the transmission rate is about 2K Bytes per second.
The problem is that my app can be killed in the background mode by iOS and I can get no indication about this. If the device start to send ble data after my app is killed, my app can only get the last data packet after it is woken up by the system and lost all the data during the wake up procedure.
How can I get all the BLE data after my app is woken up and restored by the system?
PS: I have added Bluetooth-central under UIBackgroundModes in the Info.plist. In background mode didUpdateValueForCharacteristic: method is being called. Also, a CBCentralManagerOptionRestoreIdentifierKey is specified while I construct the CBCentralManager.
On iOS you can ensure that your app isn't completely killed by the system by using State Preservation and Restoration. Please have a look at the following link for more info:-
Core Bluetooth Background Processing for iOS
However, please note that you cannot use this if you force kill the app. There's more information about this in the following question:-
BLE device keep connect with iPhone when application terminate

Connected peripheral in background mode (Core Bluetooth)

I'm trying to achieve the following scenario:
Open the app and connect to a BLE Peripheral. Working
Send the app to the background and keep the connection alive. Working
Turn off the BLE Peripheral and the app is notified of the disconnection. Working
Turn on the BLE Peripheral and the app is notified of the disconnection. Working
Turn off again the BLE Peripheral. Working
Wait 2 days with the app in background and turn on the BLE Peripheral, but the app does nothing. NOT Working
How can I achieve this last step? iOS kills the background apps when needed, but is there a way of getting notified when a previously-connected peripheral is discovered? I read something about CB State Restoration but I don't really know if this will solve this situation.
Core Bluetooth state preservation / restoration is exactly what you want. If your app is suspended, it will start you app if a peripheral connects / disconnects or a notification arrives. It is however broken by design in the way that your app will stop being woken up if Bluetooth is restarted for any reason. Examples are Bluetooth crashes (happens every now and then), if the user toggles Bluetooth or flight mode, or if the phone is restarted.

Push Notification App Running in Background When BLE is Connected

I worked on an Application which is Worked on BLE. i want push a notification ( App Running in Background When BLE is Connected) if any changes in Hardware. I Read Document
Even if your app supports one or both of the Core Bluetooth background execution modes, it can’t run forever. At some point, the system may need to terminate your app to free up memory for the current foreground app—causing any active or pending connections to be lost, for instance.
can i achieve my goal even my app in Background . If It is Possible Suggest me how to Achieve this . Thanks In Advance.
You may keep app in background by means of:
1.Audiosession(use this to play silent sound)
2.Location
3.VoIP
Any method can keep App in background and avoid App from being killed by system.
BLE Runs in the background, you need to specify that your app uses BLE Accessories or your app acts as a LE Accessory in the Background modes in app capabilities.
I've tried firing local notifications, while the application is in the background. BLE even works if the app is killed by the system, when the OS receives some communication from your peripheral or central, iOS wakes your app up and executes the desired function, before putting your app back to sleep.

iOS - wakeup application when a/any bluetooth device is connected

Is there any way to "wake-up" (relaunch) an iOS application (a background task actually, not to show the application) whenver a bluetooth device is connected?
For example, the iOS OS kills the application due to memory lack. Then a couple of hours later the user connects his bluetooth device. Can the iOS notify my application that the bluetooth device is connected and run a background task?
In Android I see that I can create a BroadcastReceiver that is registered for when a bluetooth device is connected. I need something equivalent to that for iOS.
If you have a pending connect for your BLE peripheral and you have specified BLE central background mode then yes, your app will be relaunched. You also need to implement state preservation and restoration as described in the Core Bluetooth programming guide in the event that your app is actually killed (not just in the background).
Note that in iOS a user cannot connect to a BLE peripheral directly - your app is responsible for identifying the target BLE peripheral and issuing the connect command. This is described in the programming guide.

Resources