Run background task when device sleep

We are currently developing an application that allows Bluetooth connection to hardware devices as well as collecting user health information. When the user is using a device connected via Bluetooth, we can get information from that device and store it via API.

We currently want to create a background task that will get device information via Bluetooth every 10 seconds and send it. It will run even when the iPhone is in sleep mode. I have tried many ways, but these tasks will be closed after less than 1 minute when the user sleeps. I don't know if Apple has a separate mechanism for this job or is there a way to implement this feature.

Answered by Engineer in 799851022

First, you will want to start by reading the document here: Core Bluetooth Background Processing for iOS Apps

Generally it is not possible for an app to schedule a background task every 10 seconds, or any other specific time interval, for that matter.

What you would be able to do is, though, control this schedule from the Bluetooth accessory your app is connecting to. Your app can connect to the accessory, and listen for changes to a specific characteristic. Then the accessory can update this characteristic, which will wake up your app at a set schedule or whenever it has updated data, and your app can then read and process that data (keep in mind that you will only have a few seconds to do that at each update)

Once you read the document I linked above, you will see how this all works. Basically, your app connects and waits, and the accessory controls the wakes and data transfer. That is how you could make this work with a BLE device.


Argun Tekant /  DTS Engineer / Core Technologies

First, you will want to start by reading the document here: Core Bluetooth Background Processing for iOS Apps

Generally it is not possible for an app to schedule a background task every 10 seconds, or any other specific time interval, for that matter.

What you would be able to do is, though, control this schedule from the Bluetooth accessory your app is connecting to. Your app can connect to the accessory, and listen for changes to a specific characteristic. Then the accessory can update this characteristic, which will wake up your app at a set schedule or whenever it has updated data, and your app can then read and process that data (keep in mind that you will only have a few seconds to do that at each update)

Once you read the document I linked above, you will see how this all works. Basically, your app connects and waits, and the accessory controls the wakes and data transfer. That is how you could make this work with a BLE device.


Argun Tekant /  DTS Engineer / Core Technologies

Please let me know if Apple has any mechanism to run background tasks continuously. As we see that after a short period of time, the tasks will be killed by the operating system. According to the information we have referenced, only tasks related to audio or location can run continuously in the background.

Run background task when device sleep
 
 
Q