Mit der Firebase Cloud Messaging HTTP v1 API können Sie Benachrichtigungen zu Live-Aktivitäten auf iOS-Geräten per Fernzugriff senden, aktualisieren und beenden. Für die Verwendung von Live-Aktivitäten ist iOS 16.1 erforderlich. Wenn Sie eine Benachrichtigung zu einer Live-Aktivität per Fernzugriff starten möchten, benötigen Sie iOS 17.2.
Hinweis
Bevor Sie mit Live-Aktivitäten in Firebase Cloud Messaging beginnen, folgen Sie der Anleitung unter Firebase Cloud Messaging-Client-App auf Apple Plattformen einrichten, um Firebase Cloud Messaging zu erstellen und Ihrer Client-App hinzuzufügen.
Live-Aktivität starten
Wenn Sie eine Live-Aktivität per Fernzugriff mit Firebase Cloud Messaging starten möchten, müssen Sie ein Push-to-Start Token von Apple abrufen. Außerdem benötigen Sie das FCM Registrierungs token für die Ziel-App.
Füllen Sie zum Erstellen einer Nutzlast, mit der eine Live-
Aktivität gestartet wird,
das
apns.payload Feld
aus dem folgenden Codebeispiel aus, um eine Live-Aktivität per Fernzugriff mit
FCM zu starten.
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
Klicken Sie auf Ausführen , um das Beispiel im API Explorer auszuprobieren.
Live-Aktivität aktualisieren
Wenn Sie eine Live-Aktivität per Fernzugriff mit Firebase Cloud Messaging aktualisieren möchten, müssen Sie ein Push Token von Apple abrufen. Außerdem benötigen Sie das FCM Registrierungs token für die Ziel-App.
Füllen Sie zum Erstellen einer Nutzlast, mit der eine Live
Aktivität aktualisiert wird,
das
apns.payload Feld
aus dem folgenden Codebeispiel aus, um eine Live-Aktivität per Fernzugriff mit
FCM zu aktualisieren.
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
Klicken Sie auf Ausführen , um das Beispiel im API Explorer auszuprobieren.
Live-Aktivität beenden
Wenn Sie eine Live-Aktivität mit Firebase Cloud Messaging beenden möchten, müssen Sie ein Push Token von Apple abrufen. Außerdem benötigen Sie das FCM Registrierungs token für die Ziel-App.
Füllen Sie zum Erstellen einer Nutzlast, mit der eine Live-
Aktivität beendet wird,
das Feld
apns.payload aus
dem folgenden Codebeispiel aus, um eine Live-Aktivität per Fernzugriff mit
FCM zu beenden.
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
Klicken Sie auf Ausführen , um das Beispiel im API Explorer auszuprobieren.