Can't update Live Activity from app with ActivityKit when app is running in the background with background audio playing.

I had a timer app, it played white noise after starting the timer. so my app is running in the background with background audio, and the timer is perfect for display with live activity.

However, when I test my code with a real device, I find calling await activity.update(using: contentState) when app is running in the background does not work at all. the code executes, but the live activity won't get updated.

After some experiments, I find:

  1. if the app is running in the background with background location or Picture-in-picture mode, the app can update live activity when running in the background.
  2. If the app is running in the background with audio playing, it will work on simulator, but not on a real device.

I submit a feedback: FB11683922 (Can't update Live Activity from app with ActivityKit when app is running in the background with background audio playing.)

My code is like:

  func startLiveActivity() {
    // Prepare content state and attributes.
    do {
      self.activity = try Activity.request(attributes: activityAttributes, contentState: initialContentState)
      // Play audio so app can keep running in the background.
      try playAudio() 
    } catch (let error) {
      print("Error requesting Live Activity \(error.localizedDescription).")
    }
  }

  private func playAudio() throws {
    try AVAudioSession.sharedInstance().setCategory(.playback, options: .mixWithOthers)
    try AVAudioSession.sharedInstance().setActive(true)

    if self.player == nil {
      if let url = Bundle.main.url(forResource: "Forest", withExtension: "m4a") {
        player = try AVAudioPlayer(contentsOf: url)
        player?.numberOfLoops = -1
      }
    }

    player?.stop()
    player?.currentTime = 0
    player?.play()
  }

after the timer stops, the code will execute, but the live activity won't get updated.

  func updateActivity(){
    Task {
      if let activity = self.activity {
        // Prepare content state
        await activity.update(using: contentState)
      }
    }
  }
Post not yet marked as solved Up vote post of Alen Liang Down vote post of Alen Liang
5.5k views

Replies

I'm having the same problem.

Same problem...

same problem too

It has been fixed in iOS 16.2

The same problem in iOS 16.2

Issue still present in iOS 16.2 Liveactivity updates with backgroundmode audio only work if the audio session category is set to "ambient", which makes no sense for apps which actually need to playback audio reliably.

Seems to still not work when using Audio (playback) as background mode. Too sad, makes it useless for now for round-based timer apps or anything similar.

This issue still is still occurring on iOS 16.3.

This is still an issue on iOS 16.4 beta 1

@all, you don't have to expect a solution anymore. apple is intentionally limiting the ability of media playback apps to update in the background. This conclusion has been confirmed.

This conclusion has been confirmed.

Confirmed where?

Share and Enjoy

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

  • This is an online lecture, and no screen recording is allowed, so I cannot give evidence accordingly. This online campaign is from Apple Developer Relations - Apple China Design Development Accelerator.

  • So is the current behaviour correct? This seems like a very strict limitation. We can refresh Widgets when app is in background, why not Live Activities?

Add a Comment

Same problem...

Apple responded to my report from Sept 2022 (FB11608466) and asked to verify this issue with iOS 16.5 RC.

However from my testing, this problem still occurs with iOS 16.5.

Same problem, try to update timer in dynamic island every second and it stuck after 8 seconds.