Experimenting with Reside Actions – Ole Begemann


iOS 16 beta 4 is the primary SDK launch that helps Reside Actions. A Reside Exercise is a widget-like view an app can place in your lock display and replace in actual time. Examples the place this may be helpful embody stay sports activities scores or prepare departure occasions.

These are my notes on enjoying with the API and implementing my first Reside Exercise.

A motorbike pc in your lock display

My Reside Exercise is a show for a motorbike pc that I’ve been creating with a gaggle a mates. Right here’s a video of it in motion:

And right here with simulated knowledge:

I haven’t talked a lot about our bike pc venture publicly but; that may hopefully change sometime. In brief, a gaggle of mates and I designed somewhat field that connects to your bike’s hub dynamo, measures velocity and distance, and sends the info through Bluetooth to an iOS app. The app information all of your rides and can even act as a stay speedometer when mounted in your bike’s handlebar. It’s this final function that I wished to copy within the Reside Exercise.

Comply with Apple’s information

Including a Reside Exercise to the app wasn’t exhausting. I discovered Apple’s information Displaying stay knowledge on the Lock Display screen with Reside Actions simple to comply with and fairly complete.

No express person approval

iOS doesn’t ask the person for approval when an app desires to point out a Reside Exercise. I discovered this odd because it appears to ask builders to abuse the function, however perhaps it’s OK due to the foreground requirement (see under). Plus, customers can disallow Reside Actions on a per-app foundation in Settings.

Customers can dismiss an energetic Reside Exercise from the lock display by swiping (like a notification).

Most apps will most likely must ask the person for notification permissions to replace their Reside Actions.

The app have to be within the foreground to start out an exercise

To start out a Reside Exercise, an app have to be open within the foreground. This isn’t superb for the bike pc as a result of the speedometer can’t seem magically on the lock display when the person begins using (despite the fact that iOS wakes up the app within the background at this level to ship the Bluetooth occasions from the bike). The person has to open the app manually a minimum of as soon as.

Then again, this limitation will not be a problem for many use instances and can most likely reduce down on spamming/abuse considerably.

The app should hold working within the background to replace the exercise (or use push notifications)

So long as the app retains working (within the foreground or background), it might probably replace the Reside Exercise as typically because it desires (I feel). That is superb for the bike pc because the app retains working within the background processing Bluetooth occasions whereas the bike is in movement. I assume the identical applies to different apps that may stay alive within the background, resembling audio gamers or navigation apps doing steady location monitoring.

Updating the Reside Exercise as soon as per second was no drawback in my testing, and I didn’t expertise any charge limiting.

Most apps get suspended within the background, nevertheless. They have to use push notifications to replace their Reside Exercise (or background duties or another mechanism to have the system wake you up). Apple launched a brand new sort of push notification that’s delivered on to the Reside Exercise, bypassing the app altogether. I haven’t performed with push notification updates, so I don’t know the advantages of utilizing this methodology over sending a silent push notification to wake the app and updating the Reside Exercise from there. Most likely much less aggressive charge limiting?

Lock display coloration matching

I haven’t discovered a great way to match my Reside Exercise’s colours to the present system colours on the lock display. By default, textual content in a Reside Exercise is black in gentle mode, whereas the built-in lock display themes appear to favor white or different gentle textual content colours. If there’s an API or setting worth that enables apps to match the colour fashion of the present lock display, I haven’t discovered it. I experimented with numerous foreground kinds, resembling supplies, with out success.

I ended up hardcoding the foreground coloration, however I’m not glad with the outcome. Relying on the person’s lock display theme, the Reside Exercise can look misplaced.

The default textual content coloration of a Reside Exercise in gentle mode is black. This doesn’t match most lock display themes.

Animations can’t be disabled

Apple’s information clearly states that builders have little management over animations in a Reside Exercise:

Animate content material updates

Whenever you outline the person interface of your Reside Exercise, the system ignores any animation modifiers — for instance, withAnimation(_:_:) and animation(_:worth:) — and makes use of the system’s animation timing as a substitute. Nevertheless, the system performs some animation when the dynamic content material of the Reside Exercise modifications. Textual content views animate content material modifications with blurred content material transitions, and the system animates content material transitions for photos and SF Symbols. If you happen to add or take away views from the person interface primarily based on content material or state modifications, views fade out and in. Use the next view transitions to configure these built-in transitions: opacity, transfer(edge:), slide, push(from:), or combos of them. Moreover, request animations for timer textual content with numericText(countsDown:).

It makes complete sense to me that Apple doesn’t need builders to go loopy with animations on the lock display, and maybe having full management over animations additionally makes it simpler for Apple to combine Reside Actions into the always-on show that’s most likely approaching the following iPhone.

What shocked me is that I couldn’t discover a approach to disable the textual content change animations altogether. I discover the blurred textual content transitions for the big velocity worth fairly distracting and I feel this label would look higher with none animations. However no mixture of .animation(nil), .contentTransition(.id), and .transition(.id) would do that.

A Reside Exercise could be very very similar to a widget: the UI should stay in your app’s widget extension. You begin the Reside Exercise with code that runs in your app, although. Each targets (the app and the widget extension) want entry to a standard knowledge sort that represents the info the widget shows. It’s best to have a 3rd goal (a framework or SwiftPM package deal) that accommodates such shared sorts and APIs and that the downstream targets import.

Availability annotations

WidgetBundle apparently doesn’t assist widgets with totally different minimal deployment targets. In case your widget extension has a deployment goal of iOS 14 or 15 for an current widget and also you now need to add a Reside Exercise, I’d anticipate your widget bundle to appear like this:

struct MyWidgets: WidgetBundle {
  var physique: some Widget {
    // Error: Closure containing management circulate assertion can't
    // be used with outcome builder 'WidgetBundleBuilder'
    if #accessible(iOSApplicationExtension 16.0, *) {

However this doesn’t compile as a result of the outcome builder sort utilized by WidgetBundle doesn’t assist conditionals. I hope Apple fixes this.

This wasn’t an issue for me as a result of our app didn’t have any widgets till now, so I simply set the deployment goal of the widget extension to iOS 16.0. You probably have current widgets and might’t require iOS 16 but, a workaround is so as to add a second widget extension goal only for the Reside Exercise. I haven’t tried this, however WidgetKit explicitly helps having a number of widget extensions, so it ought to work:

Sometimes, you embody all of your widgets in a single widget extension, though your app can comprise a number of extensions.


Please enter your comment!
Please enter your name here