Con l'Firebase Cloud Messaging API HTTP v1, puoi inviare, aggiornare e terminare da remoto le notifiche delle attività in tempo reale sui dispositivi iOS. Tieni presente che per utilizzare le attività in tempo reale è necessario iOS 16.1 e per avviare da remoto una notifica di attività in tempo reale è necessario iOS 17.2.
Prima di iniziare
Prima di iniziare a utilizzare le attività in tempo reale su Firebase Cloud Messaging, segui le istruzioni riportate in Configurare un'app client Firebase Cloud Messaging sulle piattaforme Apple per creare e aggiungere Firebase Cloud Messaging alla tua app client.
Avviare un'attività in tempo reale
Per avviare un'attività in tempo reale da remoto utilizzando Firebase Cloud Messaging, devi ottenere un token push-to-start da Apple. Ti servirà anche il FCM token di registrazione per l'app di destinazione.
Per creare un payload che avvii un'attività in tempo reale
,
compila il
apns.payload campo
dal seguente esempio di codice per avviare da remoto un'attività in tempo reale 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 API Explorer.
Aggiornare un'attività in tempo reale
Per aggiornare un'attività in tempo reale da remoto utilizzando Firebase Cloud Messaging, devi ottenere un token push da Apple. Ti servirà anche il FCM token di registrazione per l'app di destinazione.
Per creare un payload che aggiorni un'attività in tempo reale,
compila il
apns.payload campo
del seguente esempio di codice per aggiornare da remoto un'attività in tempo reale 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 API Explorer.
Terminare un'attività in tempo reale
Per terminare un'attività in tempo reale utilizzando Firebase Cloud Messaging, devi ottenere un token push da Apple. Ti servirà anche il FCM token di registrazione per l'app di destinazione.
Per creare un payload che termini un'attività in tempo reale
,
compila il campo
apns.payload
dal seguente esempio di codice per terminare da remoto un'attività in tempo reale 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 API Explorer.