Erste Schritte mit Live-Aktivitäten

Mit der Firebase Cloud Messaging HTTP v1 API können Sie Benachrichtigungen zu Live-Aktivitäten auf iOS-Geräten senden, aktualisieren und beenden. Für die Verwendung von Live-Aktivitäten ist iOS 16.1 erforderlich. Für das Remote-Starten einer Benachrichtigung zu einer Live-Aktivität ist iOS 17.2 erforderlich.

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 mit Firebase Cloud Messaging aus der Ferne starten möchten, müssen Sie von Apple ein Push-to-Start-Token anfordern. Außerdem benötigen Sie das FCM-Registrierungstoken für die Ziel-App.

Wenn Sie eine Nutzlast erstellen möchten, mit der eine Live-Aktivität gestartet wird, füllen Sie das Feld apns.payload aus dem folgenden Codebeispiel aus, um eine Live-Aktivität mit FCM remote 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

Ausführen

Klicken Sie auf Ausführen, um das Beispiel im API Explorer auszuprobieren.

Live-Aktivität aktualisieren

Wenn Sie eine Live-Aktivität mithilfe von Firebase Cloud Messaging remote aktualisieren möchten, müssen Sie ein Push-Token von Apple abrufen. Außerdem benötigen Sie das FCM-Registrierungstoken für die Ziel-App.

Um eine Nutzlast zu erstellen, mit der eine Live-Aktivität aktualisiert wird, füllen Sie das Feld apns.payload aus dem folgenden Codebeispiel aus, um eine Live-Aktivität mit FCM remote 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

Ausführen

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-Registrierungstoken für die Ziel-App.

Wenn Sie eine Nutzlast erstellen möchten, mit der eine Live-Aktivität beendet wird, füllen Sie das Feld apns.payload aus dem folgenden Codebeispiel aus, um eine Live-Aktivität mit FCM remote 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

Ausführen

Klicken Sie auf Ausführen, um das Beispiel im API Explorer auszuprobieren.