iOS Live Activities API
Apple 文档:
startLiveActivity
Anchor link toPOST https://api.pushwoosh.com/json/1.3/startLiveActivity
允许创建 iOS Live Activities。
请求正文
Anchor link to| 参数 | 类型 | 必需/可选 | 描述 |
|---|---|---|---|
| application | String | 必需 | Pushwoosh application code (应用代码) |
| auth | String | 必需 | 来自 Pushwoosh Control Panel 的 API access token (API 访问令牌)。 |
| notifications | Array | 必需 | 消息参数的 JSON 数组。详见下方的 Notifications 表。 |
Notifications
Anchor link to在 notifications 数组中使用的参数:
| 参数 | 类型 | 必需/可选 | 描述 |
|---|---|---|---|
| content | String | 必需 | 为运行 iOS 16.1 以下版本且不支持 Live Activity 的设备提供的备用内容。在 iOS 16.1+(支持 Live Activity)上,内容来源于 live_activity 字段。 |
| title | String | 可选 | 通知消息的标题。 |
| live_activity | Object | 必需 | 用于在 iOS 中创建 Live Activity 的 Live Activity 数据。 |
| live_activity.content-state | Object | 必需 | Live Activity 通知的内容。 |
| live_activity.attributes-type | String | 必需 | Live Activity 中使用的属性类型。 |
| live_activity.attributes | Object | 必需 | Live Activity 的属性。 |
| live_activity_id | String | 必需 | Live Activity 的唯一标识符。用于在调用 updateLiveActivity 时定位此活动。每个活动会话必须是唯一的。 |
| filter | String | 可选 | Pushwoosh 过滤器(分段)的名称。请参阅 Segment / Filter name (分段/过滤器名称)。Live Activity 将在此过滤器匹配的所有设备上启动。 |
| devices | Array of Strings | 可选 | device tokens (设备令牌) 列表。Live Activity 将仅在指定的设备上启动。 |
请求示例
Anchor link to{ "request": { "application": "XXXXX-XXXXX", "auth": "SECRET_API_TOKEN", "notifications": [ { "content": "Your order is being prepared", "title": "Food Delivery", "live_activity": { "event": "start", "title": "Order status", "content-state": { "status": "Third", "estimatedTime": "37 min", "emoji": "👨🍳" }, "attributes-type": "FoodDeliveryAttributes", "attributes": {} }, "live_activity_id": "FIRST_LIVE_ACTIVITY", "filter": "FILTER_NAME_1" } ] }}{ "request": { "application": "XXXXX-XXXXX", "auth": "SECRET_API_TOKEN", "notifications": [ { "content": "Your order is being prepared", "title": "Food Delivery", "live_activity": { "event": "start", "title": "Order status", "content-state": { "status": "Third", "estimatedTime": "37 min", "emoji": "👨🍳" }, "attributes-type": "FoodDeliveryAttributes", "attributes": {} }, "live_activity_id": "SECOND_LIVE_ACTIVITY", "devices": ["first_third", "second_device"] } ] }}响应示例
Anchor link to{ "status_code": 200, "status_message": "OK", "response": { "Messages": [ "XXXXX-XXXXXXXX-XXXXXXXX" ] }}注意:
阅读这篇文章,了解更多关于使用 Pushwoosh iOS SDK 处理 Live Activities 的信息。
updateLiveActivity
Anchor link toPOST https://api.pushwoosh.com/json/1.3/updateLiveActivity
允许更新和结束 iOS Live Activities
请求正文
Anchor link to| 参数 | 类型 | 必需/可选 | 描述 |
|---|---|---|---|
| auth | String | 必需 | 来自 Pushwoosh Control Panel 的 API access token (API 访问令牌)。 |
| application | String | 必需 | Pushwoosh application code (应用代码) |
| notifications | Array | 必需 | 消息参数的 JSON 数组。详见下方的 Notifications 表。 |
Notifications
Anchor link to在 notifications 数组中使用的参数:
| 参数 | 类型 | 必需/可选 | 描述 |
|---|---|---|---|
| live_activity | Object | 必需 | 用于在 iOS 中更新 Live Activity 的 Live Activity 数据。 |
| live_activity.event | String | 必需 | 指定事件类型。使用 "update" 更新 Live Activity 或使用 "end" 关闭它。 |
| live_activity.content-state | Object | 必需 | 包含键值对的对象,用于将数据传递给 Live Activity 以更新其内容。 |
| live_activity.dismissal-date | Integer | 可选 | Live Activity 应结束的时间(以秒为单位)。 |
| live_activity_id | String | 必需 | 要更新的 Live Activity 的唯一标识符。必须与 startLiveActivity 中使用的 live_activity_id 匹配。更新将被分发到所有启动了此活动的设备上。 |
| live_activity.relevance-score | Integer | 可选 | 告知 iOS 系统哪个 Live Activity 的优先级高于其他活动。接受从 1 到无穷大的值(建议使用 100 以下的值)。 |
| live_activity.stale-date | Integer | 可选 | 表示 Live Activity 变为过时或过期的日期的时间(以秒为单位)。 |
请求示例
Anchor link to{ "request": { "application": "XXXXX-XXXXX", "auth": "SECRET_API_TOKEN", "notifications": [ { "live_activity": { "event": "update", "title": "Live Activity Update", "content-state": { "status": "second 66", "estimatedTime": "66 min", "emoji": "👨" }, "relevance-score": 60 }, "live_activity_id": "FIRST_LIVE_ACTIVITY" } ] }}响应示例
Anchor link to{ "status_code": 200, "status_message": "OK", "response": { "Messages": [ "XXXXX-XXXXXXXX-XXXXXXXX" ] }}阅读这篇文章,了解更多关于使用 Pushwoosh iOS SDK 处理 Live Activities 的信息。
每个设备的多个活动
Anchor link to您可以通过多次调用 startLiveActivity 并使用不同的 live_activity_id 值,在同一设备上启动多个 Live Activities。
例如,如果您启动两个活动:使用 filter: FILTER_NAME_1 的 FIRST_LIVE_ACTIVITY 和使用 filter: FILTER_NAME_2 的 SECOND_LIVE_ACTIVITY,那么同时匹配这两个过滤器的设备将同时运行这两个活动。
要更新其中一个活动,请将其 live_activity_id 传递给 updateLiveActivity。更新将被分发到所有创建了该活动的设备上。另一个活动不受影响。
当同一设备上有多个 Live Activities 处于活动状态时,relevance-score 参数控制显示优先级。如果屏幕空间有限或活动被分组,则值较高的活动将以更高的优先级显示。