Con l'API HTTP v1 di Firebase Cloud Messaging, puoi inviare, aggiornare e terminare da remoto le notifiche delle attività in tempo reale sui dispositivi iOS. Tieni presente che per utilizzare l'attività in tempo reale è necessario iOS 16.1, mentre per avviare da remoto una notifica di attività in tempo reale è necessario iOS 17.2.
Prima di iniziare
Prima di iniziare a utilizzare l'attività live su Firebase Cloud Messaging, segui le istruzioni riportate in Configura un'app client Firebase Cloud Messaging su piattaforme Apple per creare e aggiungere Firebase Cloud Messaging alla tua app client.
Avvia un'attività in tempo reale
Per avviare un'attività live da remoto utilizzando Firebase Cloud Messaging, devi ottenere un token push-to-start da Apple. Avrai anche bisogno del token di registrazione FCM per l'app di destinazione.
Per creare un payload che avvia un'attività live, compila il campo apns.payload dell'esempio di codice seguente per avviare da remoto un'attività live utilizzando 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
Fai clic su Esegui per provare l'esempio in Explorer API.
Aggiorna un'attività in tempo reale
Per aggiornare un'attività live da remoto utilizzando Firebase Cloud Messaging, devi ottenere un token push da Apple. Avrai anche bisogno del token di registrazione FCM per l'app di destinazione.
Per creare un payload che aggiorna un'Attività live, compila il campo apns.payload dell'esempio di codice seguente per aggiornare da remoto un'Attività live utilizzando 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
Fai clic su Esegui per provare l'esempio in Explorer API.
Termina un'attività in tempo reale
Per terminare un'attività live utilizzando Firebase Cloud Messaging, devi ottenere un token push da Apple. Avrai anche bisogno del token di registrazione FCM per l'app di destinazione.
Per creare un payload che termina un'attività live, compila il campo apns.payload dall'esempio di codice seguente per terminare da remoto un'attività live utilizzando 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
Fai clic su Esegui per provare l'esempio in Explorer API.