herd
herd

Reputation: 195

Update live activity without push notifications and with the app in background

Is there any other way to update the live activities besides using push notifications when the app is in background?

Is it possible to schedule an update, for example?

For context, I have a live activity that needs the content updated 2 hours after it's creation.

I know that the best way to do it is using a push notification, but right now I don’t have the resources to implement this.

I already tried using BackgroundTasks, but they are not very reliable, so I can't trust it.

Upvotes: 5

Views: 2495

Answers (2)

Gabriel Sória
Gabriel Sória

Reputation: 412

I asked Apple about the reliability of background tasks for Live Activities, and here is their response:

"This is a question we get a lot! While it's possible to update a Live Activity from a background task, this functionality should not be relied upon. Background tasks are not expected to run immediately, and are only really meant to be used for fetching data to update your app in the background for the next time it's launched. Updating a Live Activity can be done from any preexisting background runtime your app already has, or by using APNs pushes to send updated data directly to users' devices."

I've got from this: If we want a reliable Live Activity, we have to use APNS.

Upvotes: 5

kamrul
kamrul

Reputation: 55

you can use pod 'Schedule' to Scheduling a task ex:

        //1. define your plan:
        let plan = Plan.after(3.seconds)

        // 2. do your task:
        let task = plan.do {
            print("3 seconds passed!")
        }

for more details please follow the link: https://github.com/luoxiu/Schedule

Upvotes: -5

Related Questions