Leveraging the Power of Background Execution (Pt. 1)

Felipe Ricieri
Kin + Carta Created
5 min readSep 6, 2020

--

How to effectively distribute and defer work from the foreground to the background.

Shot by Sergey Zolkin, in Unsplash

Last year Apple's Software Battery Life Team introduced in the WWDC the brand new BackgroundTasks Framework. It's a very lightweight — yet powerful — library, it holds only 7 new classes (2 being abstract). It mainly exposes APIs we can use to schedule tasks to run in the background.

Background Tasks isn't a new thing, though. It's been around since iOS 7, with a different — and now deprecated — API. When first introduced, it was aimed to help your app to keep the content up-to-date for the user, a routine named "App Refresh".

The way it works is pretty straightforward — We register handlers for tasks when the app launches and schedule them as required. The system will launch the app in the background and execute these tasks.

One of the coolest things about this framework is that it also allows us to leverage the processing power with the CPU monitor off. This can be very useful to you to train CoreML models or any other energy consuming task.

By the way — from iOS 13 on, we are able to satisfy several other background execution use cases, such as Discretionary Downloads, Background Pushes and more!

--

--