Connecting to a bluetooth device while app is terminated

Hello everyone!

I'm currently working on an iOS app developed with Swift that involves connecting to a specific ble (Bluetooth Low Energy) device and exchanging data even when the app is terminated or running in the background.

I'm trying to figure out a way to wake up my application when a specific Bluetooth device(uuid is known) is visible and then connect to it and exchange data.

Is this functionality achievable?

Thank you in advance for your help!

This will depend on what you mean by terminated. If the app has crashed, or has been terminated by the system (for example due to resource constraints), then yes, implementing Bluetooth State Restoration will relaunch your app.

If you want to be able to do this after the user has force quit your app, that is not going to be possible.

This tech note explains when your app can or cannot be relaunched for interacting with BLE accessories TN3115: Bluetooth State Restoration App Relaunch Rules https://developer.apple.com/documentation/dts-technotes/tn3115-bluetooth-state-restoration-app-relaunch-rules

You can read more about Bluetooth State Restoration here: Core Bluetooth Programming Guide, State Preservation and Restoration

<https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html#//apple_ref/doc/uid/TP40013257-CH7-SW5>

First of all, thank you for your response!

When i say terminated i meant swipe killed by the user. I would like to wake up my app to work in background (for a limited time, like 10 seconds) when a certain uuid or service cbuuid is near and detected by bluetooth. I think is something similar with notification system from applications, because even if i swipe kill Instagram it will continue to send me notifications. I think this should be somehow achievable.

You could also look into sending a silent background push to wake up the app when it is killed. When this data message is delivered, iOS will launch your app in the background and it can connect to a saved BLE peripheral to transmit data. While it is possible to work, the delivery is not 100% reliable and depends on a number of factors like low power modes, system budgets, rate limiting, etc.

More info here:

You could also look into sending a silent background push to wake up the app when it is killed.

If the user has signal that they don’t want your app running in the background by swiping up in the multitasking UI, your app will not receive silent push notifications.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Connecting to a bluetooth device while app is terminated
 
 
Q