Updating Live Activities without using push notifications

1k views Asked by At

I have a progress indicator in the Live Activity that should update every 15 minutes. I know that the way to go is using Push Notifications but they are not an option for me.

I have seen Apps on the Appstore and even the native timer update their live activities when push notifications are not enabled and even background App fetch is disabled.

In Apple's docs, it is mentioned that you can update or end a Live Activity from your app while it runs in the background — for example, by using Background Tasks.

Background Tasks do not work for me since they are unreliable. However, I have the Audio, Airplay, and Picture in Picture Background mode activated (For purposes other than the Live Activity) and so when I run this code:

timer = Timer(timeInterval: 1, repeats: true, block: { [weak self] (timer) in
    guard let self = self else { return }
                        
    self.value += 1
    let state = TempAttributes.ContentState(timer: self.value)
    Task { @MainActor in
       await deliveryActivity.update(using: state)
    }
})
                    
RunLoop.main.add(timer!, forMode: .common)

It technically should work and when I add a break point in the timer, it gets called and the value gets updated but the Live Activity UI does not.

This works on 16.2 but unfortunately it does not work on 16.1! Any ideas why?

0

There are 0 answers