Third clue
Etienne Vautherin - 2024/06/06
This article is part of the detective fiction about iOS 18
Activity can breathe in the background.
This third clue is perhaps the most significant one: there are videos to support the facts. And these videos are recorded at WWDC 2023.
In “Discover Streamlined Location Updates”, Siraj says: “Live Activity is the best way to enable background location updates”.
He then announces that, without a Live Activity, the way to add such a powerful feature to an existing app is to create a CLBackgroundActivitySession
. Thus, Activity
appears as a magical object that enables background tasks.
The explanation is that Live Activity or CLBackgroundActivitySession
aren’t in deep background mode: they both remain visible on the surface due to the Dynamic Island or the location indicator at the top of the screen.
This strong link between background running and a Live Activity is also confirmed by Sirisha in “Build a multi-device workout app”. She says: “HealthKit launches my companion iPhone app in the background, gives my app 10 seconds to start a Live Activity…”
However, let us return to our obscure affair and try to imagine how the \(g\) function could be created with a composition of activities (as stated in the previous clue).
Composing an activity \(A\) and another activity \(B\) often means that \(A\) exchanges a data flow with \(B\).
An Activity
is a Swift class
, and isolation rules imply that such a class
cannot produce a data flow when bathed in a concurrency environment. So, a Swift actor
needs to be instantiated around the data flow. And this mysterious actor
is currently anonymous.
However, we have two additional clues:
- Documentation for
CLBackgroundActivitySession
says that it is used “to start a background activity session”. - In “Meet Core Location Monitor”, Nivash says: “CLMonitor is a top level Swift actor… the existing one will be opened”. Guess what could be opened? Again, it is a session!
And there is even a last clue in “Build a multi-device workout app”. Data is exchanged and activities are contained in a session.
So here is the probable scenario:
When a data flow is asked to an Activity
, an activity session is created around the activity. And, when the data flow is subscribed, this session is opened.
The composition of activities describes relationships. These relationships are translated into data flows by the SwiftUI runtime provided by iOS 18. And this beautiful process is purely declarative:
- no explicit start/stop,
- no launch,
- no imperative instruction.
We are now ready to charge Activity
for the declaration of the \(g\) function!