Help Needed: Implementing a Countdown Timer Live Activity with Push Notifications

  1. Notifying the Live Activity When Countdown is Complete:

Once the countdown timer reaches zero, how do I notify the live activity? What is the best approach to ensure the live activity updates accurately and promptly?

  1. Handling App Suspension in the Background:

When my app is in the background, it gets suspended. Should I set up a job queue on the backend to send an update push notification when the timer ends? Is there a more efficient way to handle this?

  1. Ensuring Timer Accuracy:

Since this feature deals with time, I am concerned about the accuracy of the timer. How can I ensure the countdown timer remains accurate even when the app is not in the foreground?

Any answers, insights, or guidance on these issues would be greatly appreciated. Thank you in advance for your help!

Answered by DTS Engineer in 789256022

Unfortunately there are some unsolvable problems here:

Notifying the Live Activity When Countdown is Complete: Once the countdown timer reaches zero, how do I notify the live activity? What is the best approach to ensure the live activity updates accurately and promptly?

While you can notify the activity as usual to update or end the activity (see Starting and updating Live Activities with ActivityKit push notifications), this requires your app to be running at the time. As you have already noticed, in the background your app will be suspended, and won't be able to run any code, including timers to be able to know when the timer reaches zero, or update the Live Activity.

Handling App Suspension in the Background: When my app is in the background, it gets suspended. Should I set up a job queue on the backend to send an update push notification when the timer ends? Is there a more efficient way to handle this?

Your app will get suspended in the background. There is no way to prevent that unless you are using the APIs for map navigation or playing audio. And you would don't be permitted to use those unless your app has navigation or audio playing functionalities. Updating your Live Activity with push notifications is your only viable option here.

Ensuring Timer Accuracy: Since this feature deals with time, I am concerned about the accuracy of the timer. How can I ensure the countdown timer remains accurate even when the app is not in the foreground?

This depends on what kind of accuracy you are looking for. While you can control your timer start/stops via push notifications, some network latency is unavoidable. And it would also be impossible to guess under what kind of network conditions your users would be under at any given time. Whether the average delay would be acceptable for your users will depend on your use case and the expectations of your users.

Unfortunately there are some unsolvable problems here:

Notifying the Live Activity When Countdown is Complete: Once the countdown timer reaches zero, how do I notify the live activity? What is the best approach to ensure the live activity updates accurately and promptly?

While you can notify the activity as usual to update or end the activity (see Starting and updating Live Activities with ActivityKit push notifications), this requires your app to be running at the time. As you have already noticed, in the background your app will be suspended, and won't be able to run any code, including timers to be able to know when the timer reaches zero, or update the Live Activity.

Handling App Suspension in the Background: When my app is in the background, it gets suspended. Should I set up a job queue on the backend to send an update push notification when the timer ends? Is there a more efficient way to handle this?

Your app will get suspended in the background. There is no way to prevent that unless you are using the APIs for map navigation or playing audio. And you would don't be permitted to use those unless your app has navigation or audio playing functionalities. Updating your Live Activity with push notifications is your only viable option here.

Ensuring Timer Accuracy: Since this feature deals with time, I am concerned about the accuracy of the timer. How can I ensure the countdown timer remains accurate even when the app is not in the foreground?

This depends on what kind of accuracy you are looking for. While you can control your timer start/stops via push notifications, some network latency is unavoidable. And it would also be impossible to guess under what kind of network conditions your users would be under at any given time. Whether the average delay would be acceptable for your users will depend on your use case and the expectations of your users.

Help Needed: Implementing a Countdown Timer Live Activity with Push Notifications
 
 
Q