Live Activity Stops Updating after iPhone Lock

My background audio app stops updating its Live Activity after the iPhone locks, and doesn't resume updating the activity after tapping the screen or even after FaceID unlocks the device (without opening the lock screen).

My live activity requests a ContentState update & iOS updates the content for the activity as below:

Task{
		log.debug("LiveActivityManager.updateLiveActivity() with new ContentState")
		await liveActivity.update( ActivityContent(state:contentState, staleDate:nil) )
}

Below what my log looks like:

<<<<SWIPE LOCK SCREEN DOWN>>>>
DEBUG:	LiveActivityManager.updateLiveActivity() with new ContentState
iOS: Updating content for activity 0A519263-1E46-4BB6-BA4F-F3DDBC081AB4

DEBUG:	LiveActivityManager.updateLiveActivity() with new ContentState
iOS: Updating content for activity 0A519263-1E46-4BB6-BA4F-F3DDBC081AB4

<<<<PRESS LOCK BUTTON->Lock iPhone>>>>
INFO:	--------protectedDataWillBecomeUnavailableNotification--------

DEBUG:	LiveActivityManager.updateLiveActivity() with new ContentState
iOS: Updating content for activity 0A519263-1E46-4BB6-BA4F-F3DDBC081AB4

DEBUG:	LiveActivityManager.updateLiveActivity() with new ContentState
DEBUG:	LiveActivityManager.updateLiveActivity() with new ContentState
DEBUG:	LiveActivityManager.updateLiveActivity() with new ContentState

<<<<LOOK AT & TAP LOCK SCREEN->Unlock iPhone without swiping up>>>>
INFO:	--------protectedDataDidBecomeAvailableNotification-----------

DEBUG:	LiveActivityManager.updateLiveActivity() with new ContentState
DEBUG:	LiveActivityManager.updateLiveActivity() with new ContentState
DEBUG:	LiveActivityManager.updateLiveActivity() with new ContentState

As shown in the log, normally iOS updates the content for my activity after my liveActivity.update request.

This works fine in the Dynamic Island and when after switching apps and swiping down to see the lock screen without locking the phone.

However, once I lock the phone, iOS stops updating the Live Activity content, and doesn't resume updates until after the app regains the foreground at least once.

Has anyone else encountered this behavior? Is this a setting that I'm missing, or a bug?

Replies

I’m going to start you out with a pointer to this thread. Please read it through and reply here if you have follow-up questions.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks for the pointer, Quinn, but I'm afraid that doesn't answer my question. My app is using the "background audio mode" and successfully running in the background both when the device is unlocked & when it's locked. (I know it's running in the background because I can hear the audio it generates and see new statements in the log)

The problem is, even though my app is running in the background and pushing live activity content updates, iOS stops updating content after the screen is locked and doesn't resume until the user opens the app in the foreground. (Again, the app is running, generating audio, and log statements continually - it's ONLY the live activity that stops updating)

Below is the method I'm using to update the live activity:

	fileprivate func updateLiveActivity(liveActivity:ActivityKit.Activity<LiveActivityAttributes>, contentState:LiveActivityAttributes.ContentState){
		log.debug("LiveActivityManager.updateLiveActivity() with new ContentState")
		Task{
			await liveActivity.update( ActivityContent(state:contentState, staleDate:nil) )
		}
	}

A shown in the log above, I normally see my log.debug message immediately followed by an iOS generated "Updating content for activity <UUID>" message, but the iOS update message only updates once after the protectedDataWillBecomeUnavailableNotification, so my live activity display is out of date until the user returns my app to the foreground.

Thanks for the clarification. Sadly, I’ve reached the end of my Live Activities expertise )-: We’ll have to see if someone with more experience chimes in.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Apps using the background audio mode with the common audio modes cannot actually update live activites; an update silently fails; they do not update nor do they throw an error.

This is mentioned in this thread: https://developer.apple.com/forums/thread/716458 and I have confimed the behavior. This is contrary to the documentation which implies any backgrounded app can update the activity, and has wasted a lot of peoples' time, especially since it doesn't throw an error, it just doesn't work.

Workarounds would be to use an unnecessary background mode like location, or spam push notifications which will update the live activity widget as long as the user receives them.

APNs with frequent updates enabled is the supported way to update a Live Activity that needs a lot of updates. Other background types can allow for more frequent updates, but this behavior is not explicitly supported.