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-
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-
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} 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.