With the Firebase Cloud Messaging HTTP v1 API, you can remotely send, update, and end live activity notifications on iOS devices. Note that you need iOS 16.1 to use live activity and iOS 17.2 to remotely start a live activity notification.
Before you begin
Before you get started with live activity on Firebase Cloud Messaging, follow the instructions in Set up a Firebase Cloud Messaging client app on Apple platforms to create and add Firebase Cloud Messaging to your client app.
Start a live activity
To start a live activity remotely using Firebase Cloud Messaging, you need to obtain a push-to-start token from Apple. You will also need the FCM registration token for the target app.
To construct a payload that starts a live
activity,
fill in the
apns.payload
field
from the following code sample to remotely start a live activity using
FCM.
REST
{ "message": { "token": "FCM_TOKEN", "apns": { "live_activity_token": "LIVE_ACTIVITY_PUSH_TO_START_TOKEN", "headers": { "apns-priority": "10" }, "payload": { "aps": { "timestamp": TIMESTAMP, "event": "start", "content-state": { "demo": 1 }, "attributes-type": "DemoAttributes", "attributes": { "demoAttribute": 1 }, "alert": { "title": "test title", "body": "test body" } } } } } }
cURL
curl -X POST -H "Authorization: Bearer OAUTH2_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{ "message": { "token": "FCM_TOKEN", "apns": { "live_activity_token": "LIVE_ACTIVITY_PUSH_TO_START_TOKEN", "headers": { "apns-priority": "10" }, "payload": { "aps": { "timestamp": TIMESTAMP, "event": "start", "content-state": { "demo": 1 }, "attributes-type": "DemoAttributes", "attributes": { "demoAttribute": 1 }, "alert": { "title": "test title", "body": "test body" } } } } } }' https://fcm.googleapis.com/v1/projects/YOUR_PROJECT_ID/messages:send
Click Run to try the sample in the API Explorer.
Update a live activity
To update a live activity remotely using Firebase Cloud Messaging, you need to obtain a push token from Apple. You will also need the FCM registration token for the target app.
To construct a payload that updates a Live
Activity,
fill in the
apns.payload
field
from the following code sample to remotely update a live activity using
FCM.
REST
{ "message": { "token": "FCM_TOKEN", "apns": { "live_activity_token": "LIVE_ACTIVITY_PUSH_TOKEN", "headers": { "apns-priority": "10" }, "payload": { "aps": { "timestamp": TIMESTAMP, "event": "update", "content-state": { "test1": 100, "test2": "demo" }, "alert": { "title": "test title", "body": "test body" } } } } } }
cURL
curl -X POST -H "Authorization: Bearer OAUTH2_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{ "message": { "token": "FCM_TOKEN", "apns": { "live_activity_token": "LIVE_ACTIVITY_PUSH_TOKEN", "headers": { "apns-priority": "10" }, "payload": { "aps": { "timestamp": TIMESTAMP, "event": "update", "content-state": { "test1": 100, "test2": "demo" }, "alert": { "title": "test title", "body": "test body" } } } } } }' https://fcm.googleapis.com/v1/projects/YOUR_PROJECT_ID/messages:send
Click Run to try the sample in the API Explorer.
End a live activity
To end a live activity using Firebase Cloud Messaging, you need to obtain a push token from Apple. You will also need the FCM registration token for the target app.
To construct a payload that ends a live
activity,
fill in the
apns.payload
field
from the following code sample to remotely end a live activity using
FCM.
REST
{ "message": { "token": "FCM_TOKEN", "apns": { "live_activity_token": "LIVE_ACTIVITY_PUSH_TOKEN", "headers": { "apns-priority": "10" }, "payload": { "aps": { "timestamp": TIMESTAMP, "dismissal-date": DISMISSAL_DATE, "event": "end", "content-state": { "test1": 100, "test2": "demo" }, "alert": { "title": "test title", "body": "test body" } } } } } }
cURL
curl -X POST -H "Authorization: Bearer OAUTH2_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{ "message": { "token": "FCM_TOKEN", "apns": { "live_activity_token": "LIVE_ACTIVITY_PUSH_TOKEN", "headers": { "apns-priority": "10" }, "payload": { "aps": { "timestamp": TIMESTAMP, "dismissal-date": DISMISSAL_DATE, "event": "end", "content-state": { "test1": 100, "test2": "demo" }, "alert": { "title": "test title", "body": "test body" } } } } } }' https://fcm.googleapis.com/v1/projects/YOUR_PROJECT_ID/messages:send
Click Run to try the sample in the API Explorer.