2

I have applied below logic: Can I make an api call when the user terminates the app? to fetch contents from the API to update liveActivity when app terminates

Is it a feasible solution?

Code snippet-

enter image description here

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Shruti
  • 21
  • 1
  • Hi and welcome to Stack Overflow. As an advice for your first question, it should focus on the bare problem you’re trying to solve to get more feedback, in this case executing a web request when the application is terminated. The title must reflect that more clearly and the content should set a bit more context and why you want to achieve that. Also, your code snippet should be written inside your post instead of inserted as an image, it helps other people and search engines to find your question. – Crazyrems Jan 30 '23 at 08:54
  • If the user terminates the app they are likely not interested in live updates. – lorem ipsum Jan 30 '23 at 10:26
  • you can start a live activity when the app is the foreground, update it when the app is in fore or background. If you terminate the app you can not update it. you can use e.g silent push or background tasks to update it in background but no way to update if you kill the app. – Ilker Baltaci Apr 26 '23 at 12:32

1 Answers1

0

You can use a remote push notification to update the live activity when the app is killed by the following the below steps. It is very similar to a regular remote push notification but with few changes:

1- You will need to configure the request headers:

  • apns-topic with a value of "{APNS_TOPIC}.push-type.liveactivity"
  • apns-push-type with a value of "liveactivity"
  • authorization with a value of "bearer {JWT}"
  • Content-Type with a value of "application/json"

{APNS_TOPIC} should be your app Bundle ID

2- You will need to send the following in the payload:

      {
        "aps":{
           "timestamp":1673300490, 
           "event":"update", 
        "content-state":{
           "progress": "10"
        }, 
        "alert":{
           "title":"Update",
           "body":"My Live Activity has been updated remotely" }
        } 
      }

3- To end the live activity, you should replace "update" with "end" and add a new parameter below it called "dismissal-date", which should be in epoch time. Note that if you put a time in the past it will be destroyed immediately.

That's it! After sending this push notification from your server, your live activity should be updated accordingly.

Hashim
  • 1
  • 2