iOS Live Activities API
Apple 文档:
startLiveActivity
Anchor link to使用此方法创建 iOS Live Activities。
POST 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。 |
| notifications | Array | 必需 | 消息参数的 JSON 数组。详情请参见下方的 Notifications 表。 |
Notifications
Anchor link tonotifications 数组中使用的参数:
| 参数 | 类型 | 必需/可选 | 描述 |
|---|---|---|---|
| content | String | 必需 | 为运行 iOS 16.1 以下版本且不支持 Live Activity 的设备提供的备用内容。在 iOS 16.1+(支持 Live Activity)上,内容来源于 live_activity 字段。 |
| title | String | 可选 | 通知消息的标题。 |
| live_activity | Object | 必需 | 用于在 iOS 中创建 Live Activity 的 Live Activity 数据。 |
| content-state | Object | 必需 | Live Activity 通知的内容。 |
| attributes-type | String | 必需 | Live Activity 中使用的属性类型。 |
| attributes | Object | 必需 | Live Activity 的属性。 |
| live_activity_id | String | 必需 | 由用户创建的 Live Activity 的唯一 ID。 |
| filter_code | String | 可选 | 用于定位特定受众群体的 Filter (Segment) code。 |
| devices | Array of strings | 可选 | 用于发送定向推送通知的 Tokens 或 HWIDs,最多 1000 个。如果设置,消息将仅发送到列表中的设备。注意: 不允许为设备列表使用 Application Group,且 iOS 推送令牌必须为小写。 |
| users | Array of strings | 可选 | 如果设置,消息将仅传递给指定的 User ID(通过 /registerUser 调用分配)。您可以在数组中包含最多 1000 个用户 ID。注意: 如果与 devices 参数一起使用,users 参数将优先。不允许为用户列表使用 Application Group。 |
200
{ "status_code": 200, "status_message": "OK", "response": { "Messages": [ "C3F8-C3863ED4-334AD4F1" ] }}请求示例
Anchor link to{ "request": { "application": "XXXXX-XXXXX", // 必需。Pushwoosh application code "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh Control Panel 的 API access token "notifications": [{ "live_activity": { // 必需。用于在 iOS 中创建 Live Activity 的 Live Activity 数据 "content-state": { "emoji": ":wink:" }, "attributes-type": "LiveActivityAttributes", "attributes": { "name": "Apple" } }, "live_activity_id": "unique UUID", // 可选。Live Activity 的唯一标识符。 "filter_code": "FILTER_NAME", // 可选。指定 filter。 "devices": [ // 可选。指定 tokens 或 hwids 以发送定向推送 "hwid_XXXX" // 通知。数组中不超过 1000 个 tokens/hwids。 ], // 如果设置,消息将仅发送到 // 列表中的设备。不允许为设备列表 // 使用 Application Group。 // iOS 推送令牌只能是小写。 "users": [ // 可选。如果设置,消息将仅传递给指定的 "user_XXXX" // 用户 ID(通过 /registerUser 调用设置)。如果 ] // 与 devices 参数一起指定,后者将被 // 忽略。数组中不超过 1000 个用户 ID。 // 不允许为用户列表使用 Application Group。 }] }}注意:
阅读这篇文章,了解更多关于使用 Pushwoosh iOS SDK 处理 Live Activities 的信息。
updateLiveActivity
Anchor link to使用此方法管理 iOS Live Activities。
POST https://api.pushwoosh.com/json/1.3/updateLiveActivity
允许创建和管理 iOS Live Activities。
请求正文
Anchor link to| 参数 | 类型 | 必需/可选 | 描述 |
|---|---|---|---|
| auth | String | 必需 | 来自 Pushwoosh Control Panel 的 API access token。 |
| application | String | 必需 | Pushwoosh application code |
| notifications | Array | 必需 | 消息参数的 JSON 数组。详情请参见下方的 Notifications 表。 |
Notifications
Anchor link tonotifications 数组中使用的参数:
| 参数 | 类型 | 必需/可选 | 描述 |
|---|---|---|---|
| live_activity | Object | 必需 | 用于在 iOS 中更新 Live Activity 的 Live Activity 数据。 |
| event | String | 必需 | 指定事件类型。使用 “update” 更新 Live Activity 或使用 “end” 关闭它。 |
| content-state | Object | 必需 | 包含键值对的对象,用于将数据传递给 Live Activity 以更新其内容。 |
| dismissal-date | Integer | 可选 | Live Activity 应结束的时间(以秒为单位)。 |
| live_activity_id | String | 必需 | 正在更新的 Live Activity 的唯一标识符。 |
| relevance-score | Integer | 可选 | 告知 iOS 系统哪个 Live Activity 比其他 Live Activity 具有更高的优先级。接受从 1 到无穷大的值(建议值最高为 100)。 |
| stale-date | Integer | 可选 | 表示 Live Activity 变为过时或过期的日期的时间(以秒为单位)。 |
{ "status_code": 200, "status_message": "OK", "response": { "Messages": [ "C3F8-C3863ED4-334AD4F1" ] }}请求示例
Anchor link to{ "request": { "application": "XXXXX-XXXXX", // 必需。Pushwoosh application code "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh Control Panel 的 API access token "notifications": [{ "live_activity": { // 必需。用于在 iOS 中更新 Live Activity 的 Live Activity 数据 "event": "update", // 必需。使用 "update" 更新 Live Activity 或 // 使用 "end" 关闭 Live Activity "content-state": { // 必需。包含键值对的对象,用于传递数据 "courierName": "NUMBER: 15", // 给 Live Activity 以更新其内容 "deliveryStatus": "Done" }, "dismissal-date": 12345678, // 可选。结束 Live Activity 的时间(以秒为单位) "relevance-score": 50, // 可选。Live Activity 的优先级(建议 1 到 100) "stale-date": 23456789 // 可选。Live Activity 变为过时的时间(以秒为单位) }, "live_activity_id": "unique UUID" // 可选。Live Activity 的唯一标识符。 }] }}阅读这篇文章,了解更多关于使用 Pushwoosh iOS SDK 处理 Live Activities 的信息。