How do I begin development for Live Activities?

Follow Apple’s docs:

  • Add a new† (widget) target to your app. Make sure you select ‘Live Activities’.
  • Add the necessary plist items.
  • Add push notification capability. Only needed if you want to start / update from server. If everything is done from within the app then you don’t need this. Example ‘Clock’ App on iPhone adds timers to your phone without any server interaction.
  • Not sure why but by adding the widget, Xcode automatically adds a TimelineProvider. It’s useless for Live Activities. You can delete it.

Note: A widget is a specific kind of app extension.

Does killing the app stop an active Live Activity?

No. For me it remained in Dynamic Island and Lock screen

Does killing the app cause live activities not to be delivered?

My live activity was able to get started. I haven’t tested yet if my app gets callbacks or not…

What’s the feature difference between a Live Activity and a Regular Push Notification?

Notifications have a fixed layout, with no ability to animate nor buttons to interact with.

Live Activities have custom UI and are far richer. Can be animated up to two seconds (with some exceptions. See here). Can also have buttons added onto them. Live Activity is also positioned at where the dynamic island is at. It persists on the screen and morphs into different presentations

What’s the difference between Live Activity and Dynamic Island?

  • Dynamic Island is a physical location of certain newer models. First introduced in iPhone 14 Pro, and then on every model since then.
  • Live Activity is an Apple feature. Think of it as a shape shifting notification.
  • The Live Activity appears in the dynamic island when the phone is unlocked. If a phone doesn’t have a live activity then it appears as a notification

What forms does the Live Activity take?

Apple calls the ‘presentations’. The Live Activity can appear in multiple presentations:

  • Dynamic Island
    • Compact
    • Expanded
    • Minimal (attached or detached)
  • Lock Screen

For an in-app UI, see Does the Live Activity appear when app is in foreground? Apple requires you to have all presentations added. You can’t skip any of them.

How do I create an Expanded view?

The expanded view is made up of four sections.

“Expanded View
Expanded View

You can share the leading / Trailing views between the expanded and compact. See here

Note:

  • A Live Activity that’s started from a push Notification is immediately expanded upon its arrival. Then within a few seconds it shrinks down to a compact presentation.
  • While a live activity that’s started from the app isn’t shown immediately at all. It’s starts showing in compact presentation after app is backgrounded.

Does the Live Activity appear when app is in foreground?

Yes/No. It does not show anything. The sound within the payload also gets dropped.

For in-app experience:

  • You need your own UI. Figure out where / when you should or not show it.
  • The app does callbacks when either in foreground or background. You can rely on the ActivityUpdates for changes in content and use that to update the in-app UI.

How do live activities and regular notifications stack against each other on lock screen?

Live activities sit on top of regular notifications.

How long can a Live Activity remain on the screen?

  • Maximum of 8 hours on dynamic island
  • Maximum of 12 hours on lock screen.
  • or sooner if user dismisses it.

Can I use a start token to update an existing Live Activity?

No. You need to use an update token to update an existing live activity. When I tried that the Console logged:

Unsupported push notification event type for pushToStart subscription: update

I was actually surprised that the push notification made to the OS. I would have thought that APNS would have gated it, but perhaps their tokens are opaque enough that APNS just blindly passes them to the OS. Not sure…

How can I remove a Live Activity from the screen?

Dismissing a live activity should not cancel the activity.

There are different ways to dismiss:

  • From the compact presentation, you can swipe left on its center. You can swipe AGAIN to bring it back ‼️
  • From the expanded presentation, you can’t swipe left nor dismiss it.
  • From the lock screen presentation, you can dismiss it like regular notifications. You can NOT swipe again to bring it back.

⚠️ - Swiping from the compact presentation, only hides the Live Activity. The Live Activity will still remain on the lock while swiping on the lock screen will dismiss the Live Activity. Neither swipes should end your activity. That should be done through some explicit action.

So how can I cancel and remove an activity?

In the Apple Clock app, dismissing a Live Activity timer does NOT stop the timer. It just removes it from your dynamic island. Similarly, if you dismiss the live activity of an Uber trip, then it does NOT cancel the trip. Apple just removes the live activity from your dynamic island / screen.

If you needed to cancel an activity, then you can either add cancel buttons onto the live activity, and then allow users to cancel the timer using certain actions associated with the notification or allow users to tap on the live activity, open the app and then end it from within the app.

Cancelling should only be done upon an explicit action which should then dismiss the Live Activity for you as well.

“canceling
Apple Clock App canceling with an App Intent Action

Will the user get prompted to give access for tokens?

YES/NO. The start token is issued provisionally.

If your Live Activity is started by the _server then:
The update token though requires explicit user permission from the lock screen.

However, if your Live Activity is started by the app then:

While you still see the OS prompt to “Don’t Allow” / “Allow” the Live Activity Updates, the update token is immediately issued — regardless of user hitting Allow or not.

This inconsistent behavior and lack of ability to update Live Activities is huge source of frustration amongst engineers and product managers. This problem is also mentioned in the forums and here

I plan on filing a radar and opening a DTS ticket for this.

❕❕❕ The dilemma and proper user education

If you the duration of the activity is short and the event is started from the server, then your users will have a very short window of time to:

  1. Lock the phone
  2. Hit “Allow”. A user may actually think hitting Allow isn’t necessary, because in the case of client-started live activity, it’s not required.

If your users are slow to engage or aren’t aware of the importance to engage or simply put don’t care, then you’d experience a lot of stale activities.

Workarounds

A. Do product education for users. If you detected that the Live Activity has started then maybe you could say “You can background the app. Just make sure you hit “Allow” on the lock screen” B. Do a few Live Activities before. Especially ones that are longer. If from previous Live Activities, the user hits “Allow” and then ultimately hits “Always Allow” then the OS will grant update tokens in perpetuity. If your app intends to use Live Activities numerous times, then you should be playing the long run and not assume investment in its infrastructure isn’t worth it. C. Start Live Activity from app. This could be advantageous because update tokens are then issued immediately. This is only a good idea if the event that starts the Live Activity is triggered by the app. Often Live Activities are triggered by some external event and so you can’t rely on the app to trigger the event. Examples:

  • Arrival Events. Ex: Amazon Starting the last 5 miles towards your home, Technician en route to come and fix your internet.
  • An ioT device event. Laundry in progress, Coffee is brewing, Robot is vacuuming the house, Modem is rebooting, EV Charging, etc.

When is Live Activity not a good choice?

  • If the user has reasons to keep the app open during the time the live activity is active, then the user won’t be seeing it. For most cases you can’t predict users keeping the app open.
  • If the event is coming immediately after the initial app installation and the live activity must be started from the server, and the duration of the live activity is just a couple minutes, then it may not be a good fit — because the app hasn’t yet built a proper baseline with the OS to allow Live Activities in perpetuity.

👉 Next Post - Live Activities - Development