Run model inference in background every x minutes

Hi! I have written an app which is downloading data every x minutes and needs that to be interpreted through a CoreML model and be stored on device so the user can check when entering the app again what happened during the last hours. Is this possible? Can this be done through the whole day? And which background function do I need for that? Thanks in advance!

Accepted Reply

You should be able to have the BLE accessory trigger your app in the background without much problem. The issue is what you can do when that happens.

By default, the system will give you approximately 10 seconds of execution time once your app starts executing in response to a BLE event. You can possibly extend this to 30 seconds (maximum) by using beginBackgroundTaskWithExpirationHandler() ( details here: https://developer.apple.com/documentation/uikit/uiapplication/1623031-beginbackgroundtaskwithexpiratio )

This still falls short of the 1 minute you need, so you may have to do some juggling to fit what you need to do in these limited time slots. Perhaps you can have your accessory wake up more frequently and divide the download and prediction into separate jobs.

If you also need to personalize the model, you would definitely be better off using a background processing task to do that which will give you enough time to complete that, although that will run only once a day. More here: https://developer.apple.com/documentation/backgroundtasks

Replies

I have written an app which is downloading data every x minutes

How is it downloading data every X minutes? iOS does not, in general, support periodic network downloads while your app is in the background.

And roughly what value is X?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
The data is being logged on an external device and the idea is that every 10 minutes the app will connect in the background -> download the data from device -> do predictions -> save and start logging again for the next 10 minutes. The connection to the device and the download are working through bluetooth.

The data is being logged on an external device

How is that accessory connected?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Thanks @eskimo for the answers. You basically start the process of logging after you connect with BLE -> the data is logged on device but should be downloaded every 10 minutes so the amount of data is not getting to big. I thought it would be possible to connect to the device the same way as I would do it from foreground (in background) and then do my predictions and start a new logging process until I repeat the procedure in hopefully a scheduled way. The download from the device and predictions would need 1 minute of processing time.

You basically start the process of logging after you connect with BLE

Core Bluetooth does have some background execution features but I’m not sufficiently up to speed on them to help you out here. I’ve added the Core Bluetooth tag to this thread and hopefully that’ll attract someone who is.

If not, you should open a DTS tech support incident and speak to DTS’s Core Bluetooth specialist.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
You should be able to have the BLE accessory trigger your app in the background without much problem. The issue is what you can do when that happens.

By default, the system will give you approximately 10 seconds of execution time once your app starts executing in response to a BLE event. You can possibly extend this to 30 seconds (maximum) by using beginBackgroundTaskWithExpirationHandler() ( details here: https://developer.apple.com/documentation/uikit/uiapplication/1623031-beginbackgroundtaskwithexpiratio )

This still falls short of the 1 minute you need, so you may have to do some juggling to fit what you need to do in these limited time slots. Perhaps you can have your accessory wake up more frequently and divide the download and prediction into separate jobs.

If you also need to personalize the model, you would definitely be better off using a background processing task to do that which will give you enough time to complete that, although that will run only once a day. More here: https://developer.apple.com/documentation/backgroundtasks