How to Update Live Activity X minutes using BGTask

I want to update my live activity every X minutes but it is not working while app in background mode and app going background mode to suspend mode after some time automatically

How can i update my live activity every X minutes using background Task.

Answered by DTS Engineer in 782433022

There are two ways to update a Live Activity:

  • Programmatically

  • Using a push notification

I presume you’re interested in the first case. In order to do that, the code in your app has to be running. iOS puts strict limits on when your code is allowed to run in the background. I talk about this in iOS Background Execution Limits. I suggest you read that first and then come back here if you have follow-up questions.

Share and Enjoy

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

Accepted Answer

There are two ways to update a Live Activity:

  • Programmatically

  • Using a push notification

I presume you’re interested in the first case. In order to do that, the code in your app has to be running. iOS puts strict limits on when your code is allowed to run in the background. I talk about this in iOS Background Execution Limits. I suggest you read that first and then come back here if you have follow-up questions.

Share and Enjoy

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

If the updates is just a Timer or a Progress Bar, please use the following and it will work fine:

https://developer.apple.com/documentation/swiftui/text/init(timerinterval:pausetime:countsdown:showshours:) https://developer.apple.com/documentation/swiftui/progressview/init(timerinterval:countsdown:)

Thanks.

How to Update Live Activity X minutes using BGTask
 
 
Q