开始使用实时活动
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助 Firebase Cloud Messaging HTTP v1 API,您可以在 iOS 设备上远程发送、更新和结束实时活动通知。请注意,您需要 iOS 16.1 才能使用实时活动,需要 iOS 17.2 才能远程启动实时活动通知。
准备工作
开始在 Firebase Cloud Messaging 中使用实时活动之前,请按照设置 Firebase Cloud Messaging 客户端应用(Apple 平台)中的说明创建 Firebase Cloud Messaging 并将其添加到您的客户端应用中。
启动实时活动
如需使用 Firebase Cloud Messaging 远程启动实时活动,您需要从 Apple 获取推送启动令牌。您还需要用于目标应用的 FCM 注册令牌。
如需构建用于启动实时活动的载荷,请填写以下代码示例中的 apns.payload
字段,以使用 FCM 远程启动实时活动。您可以使用 API Explorer 构造和测试载荷。
"message":{
"token": "<fcm_token:test>",
"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"
}
}
}
}
}
更新实时活动
如需使用 Firebase Cloud Messaging 远程更新实时活动,您需要从 Apple 获取推送令牌。您还需要用于目标应用的 FCM 注册令牌。
如需构建用于更新实时活动的载荷,请填写以下代码示例中的 apns.payload
字段,以使用 FCM 远程更新实时活动。您可以使用 API Explorer 构造和测试载荷。
"message":{
"token": "<fcm_token:test>",
"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"
}
}
}
}
}
}
结束实时活动
如需使用 Firebase Cloud Messaging 结束实时活动,您需要从 Apple 获取推送令牌。您还需要用于目标应用的 FCM 注册令牌。
如需构建用于结束实时活动的载荷,请填写以下代码示例中的 apns.payload
字段,以使用 FCM 远程结束实时活动。您可以使用 API Explorer 构造和测试载荷。
"message":{
"token": "<fcm_token:test>",
"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"
}
}
}
}
}
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-16。
[null,null,["最后更新时间 (UTC):2025-08-16。"],[],[],null,["\u003cbr /\u003e\n\nWith the Firebase Cloud Messaging [HTTP v1\nAPI](/docs/reference/fcm/rest/v1/projects.messages/send), you can remotely send,\nupdate, and end live activity notifications on iOS devices. Note that you need\niOS 16.1 to use live activity and iOS 17.2 to remotely start a live activity\nnotification.\n\nBefore you begin\n\nBefore you get started with live activity on Firebase Cloud Messaging, follow the\ninstructions in [Set up a Firebase Cloud Messaging client app on Apple\nplatforms](/docs/cloud-messaging/ios/client) to create and add\nFirebase Cloud Messaging to your client app.\n\nStart a live activity\n\nTo start a live activity remotely using Firebase Cloud Messaging, you need to\nobtain a [push-to-start\ntoken](https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications#Start-new-Live-Activities-with-ActivityKit-push-notifications)\nfrom Apple. You will also need the [FCM registration\ntoken](/docs/cloud-messaging/ios/client#access_the_registration_token) for the\ntarget app.\n\nTo construct a [payload that starts a live\nactivity](https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications#Construct-the-payload-that-starts-a-Live-Activity),\nfill in the\n[`apns.payload`](/docs/reference/fcm/rest/v1/projects.messages#ApnsConfig) field\nfrom the following code sample to remotely start a live activity using\nFCM. You can use the [API\nExplorer](/docs/reference/fcm/rest/v1/projects.messages/send?apix=true&apix_params=%7B%22parent%22%3A%22projects%2F%3Cproject_number%3E%22%2C%22resource%22%3A%7B%22message%22%3A%7B%22token%22%3A%22%3Cfcm_token%3Atest%3E%22%2C%22apns%22%3A%7B%22live_activity_token%22%3A%22%3Clive_activity_push_to_start_token%3E%22%2C%22headers%22%3A%7B%22apns-priority%22%3A%2210%22%7D%2C%22payload%22%3A%7B%22aps%22%3A%7B%22timestamp%22%3A%22%3Ctimestamp%3E%22%2C%22event%22%3A%22start%22%2C%22content-state%22%3A%7B%22demo%22%3A1%7D%2C%22attributes-type%22%3A%22DemoAttributes%22%2C%22attributes%22%3A%7B%22demoAttribute%22%3A1%7D%2C%22alert%22%3A%7B%22title%22%3A%22test%20title%22%2C%22body%22%3A%22test%20body%22%7D%7D%7D%7D%7D%7D%7D)\nto construct and test your payload. \n\n```gdscript\n\"message\":{\n \"token\": \"\u003cfcm_token:test\u003e\",\n \"apns\":{\n \"live_activity_token\": \"\u003clive_activity_push_to_start_token\u003e\",\n \"headers\":{\n \"apns-priority\": \"10\"\n },\n \"payload\":{\n \"aps\": {\n \"timestamp\": \u003ctimestamp\u003e,\n \"event\": \"start\",\n \"content-state\": {\n \"demo\": 1\n },\n \"attributes-type\": \"DemoAttributes\",\n \"attributes\": {\n \"demoAttribute\": 1,\n },\n \"alert\": {\n \"title\": \"test title\",\n \"body\": \"test body\"\n }\n }\n }\n }\n }\n```\n\nUpdate a live activity\n\nTo update a live activity remotely using Firebase Cloud Messaging, you need to\nobtain a [push\ntoken](https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications#Start-a-Live-Activity-that-supports-push-updates-to-push-tokens)\nfrom Apple. You will also need the [FCM registration\ntoken](/docs/cloud-messaging/ios/client#access_the_registration_token) for the\ntarget app.\n\nTo construct a [payload that updates a Live\nActivity](https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications#Construct-the-ActivityKit-remote-push-notification-payload),\nfill in the\n[`apns.payload`](/docs/reference/fcm/rest/v1/projects.messages#ApnsConfig) field\nfrom the following code sample to remotely update a live activity using\nFCM. You can use the [API\nExplorer](/docs/reference/fcm/rest/v1/projects.messages/send?apix=true&apix_params=%7B%22parent%22%3A%22projects%2F%3Cproject_number%3E%22%2C%22resource%22%3A%7B%22message%22%3A%7B%22token%22%3A%22%3Cfcm_token%3Atest%3E%22%2C%22apns%22%3A%7B%22live_activity_token%22%3A%22%3Clive_activity_push_token%3E%22%2C%22headers%22%3A%7B%22apns-priority%22%3A%2210%22%7D%2C%22payload%22%3A%7B%22aps%22%3A%7B%22timestamp%22%3A%22%3Ctimestamp%3E%22%2C%22event%22%3A%22update%22%2C%22content-state%22%3A%7B%22test1%22%3A100%2C%22test2%22%3A%22demo%22%7D%2C%22alert%22%3A%7B%22title%22%3A%22test%20title%22%2C%22body%22%3A%22test%20body%22%7D%7D%7D%7D%7D%7D%7D)\nto construct and test your payload. \n\n```gdscript\n\"message\":{\n \"token\": \"\u003cfcm_token:test\u003e\",\n \"apns\":{\n \"live_activity_token\": \"\u003clive_activity_push_token\u003e\",\n \"headers\":{\n \"apns-priority\": \"10\"\n },\n \"payload\":{\n \"aps\": {\n \"timestamp\": \u003ctimestamp\u003e,\n \"event\": \"update\",\n \"content-state\": {\n \"test1\": 100,\n \"test2\": \"demo\"\n },\n \"alert\": {\n \"title\": \"test title\",\n \"body\": \"test body\"\n }\n }\n }\n }\n }\n}\n```\n\nEnd a live activity\n\nTo end a live activity using Firebase Cloud Messaging, you need to obtain a [push\ntoken](https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications#Start-a-Live-Activity-that-supports-push-updates-to-push-tokens)\nfrom Apple. You will also need the [FCM registration\ntoken](/docs/cloud-messaging/ios/client#access_the_registration_token)\nfor the target app.\n\nTo construct [a payload that ends a live\nactivity](https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications#Construct-the-ActivityKit-remote-push-notification-payload),\nfill in the\n[`apns.payload`](/docs/reference/fcm/rest/v1/projects.messages#ApnsConfig) field\nfrom the following code sample to remotely end a live activity using\nFCM. You can use the [API\nExplorer](/docs/reference/fcm/rest/v1/projects.messages/send?apix=true&apix_params=%7B%22parent%22%3A%22projects%2F%3Cproject_number%3E%22%2C%22resource%22%3A%7B%22message%22%3A%7B%22token%22%3A%22%3Cfcm_token%3Atest%3E%22%2C%22apns%22%3A%7B%22live_activity_token%22%3A%22%3Clive_activity_push_token%3E%22%2C%22headers%22%3A%7B%22apns-priority%22%3A%2210%22%7D%2C%22payload%22%3A%7B%22aps%22%3A%7B%22timestamp%22%3A%22%3Ctimestamp%3E%22%2C%22dismissal-date%22%3A%22%3Cdismissal_date%3E%22%2C%22event%22%3A%22end%22%2C%22content-state%22%3A%7B%22test1%22%3A100%2C%22test2%22%3A%22demo%22%7D%2C%22alert%22%3A%7B%22title%22%3A%22test%20title%22%2C%22body%22%3A%22test%20body%22%7D%7D%7D%7D%7D%7D%7D)\nto construct and test your payload. \n\n```gdscript\n\"message\":{\n \"token\": \"\u003cfcm_token:test\u003e\",\n \"apns\":{\n \"live_activity_token\": \"\u003clive_activity_push_token\u003e\",\n \"headers\":{\n \"apns-priority\": \"10\"\n },\n \"payload\":{\n \"aps\": {\n \"timestamp\": \u003ctimestamp\u003e,\n \"dismissal-date\": \u003cdismissal_date\u003e,\n \"event\": \"end\",\n \"content-state\": {\n \"test1\": 100,\n \"test2\": \"demo\"\n },\n \"alert\": {\n \"title\": \"test title\",\n \"body\": \"test body\"\n }\n }\n }\n }\n }\n}\n```"]]