首页
/ Push 包使用指南

Push 包使用指南

2024-12-23 01:35:31作者:平淮齐Percy

本文档旨在帮助用户了解如何安装、使用和调用 Push 包的相关功能。Push 包提供了与推送服务交互的能力,包括发送推送通知和处理设备活动事件。

1. 安装指南

1.1 创建 Bluemix 应用程序

首先,在 Bluemix Dashboard 中创建一个 Bluemix 应用程序。

1.2 初始化推送通知服务

在 Bluemix 应用程序中初始化推送通知服务,并将其绑定到应用程序。

1.3 配置推送通知应用程序

配置 推送通知应用程序,并确保记住 App GUIDApp Secret

1.4 创建包绑定

使用以下命令创建包绑定:

wsk package bind /whisk.system/pushnotifications myPush -p appId myAppID -p appSecret myAppSecret

1.5 验证包绑定

使用以下命令验证包绑定是否存在:

wsk package list

输出应包含类似以下内容:

packages
/myNamespace/myPush private binding

2. 项目使用说明

2.1 发送推送通知

使用 /whisk.system/pushnotifications/sendMessage 动作发送推送通知。以下是该动作的参数说明:

  • text: 推送通知的文本内容。例如:-p text "Hi, OpenWhisk send a notification"
  • url: 可选的 URL,随通知一起发送。例如:-p url "https:\\www.w3.ibm.com"
  • apiHost: 可选的 API 主机地址,默认为 mobile.ng.bluemix.net。例如:-p apiHost "mobile.eu-gb.bluemix.net"
  • deviceIds: 指定设备的列表。例如:-p deviceIds "[\"deviceID1\"]"
  • platforms: 指定平台的设备。A 表示 Apple (iOS) 设备,G 表示 Google (Android) 设备。例如:-p platforms ["A"]
  • userIds: 指定用户的设备。例如:-p userIds "[\"testUser\"]"
  • tagNames: 发送给订阅了这些标签的设备。例如:-p tagNames "[\"tag1\"]"

其他参数如 gcmCollapseKeygcmCategorygcmIcon 等,用于配置推送通知的详细选项。

2.2 示例

以下是发送推送通知的示例:

wsk action invoke /myNamespace/myPush/sendMessage -p text "Hi, OpenWhisk send a notification" -p deviceIds "[\"deviceID1\"]"

3. 项目 API 使用文档

3.1 包 /whisk.system/pushnotifications

该包包含以下动作和 feed:

  • /whisk.system/pushnotifications: 包,包含 appIdappSecret 参数,用于与推送服务交互。
  • /whisk.system/pushnotifications/sendMessage: 动作,用于发送推送通知。
  • /whisk.system/pushnotifications/webhook: feed,用于在设备活动(如注册、注销、订阅或取消订阅)时触发事件。

3.2 参数说明

  • appId: Bluemix 应用程序的 GUID。
  • appSecret: Bluemix 推送通知服务的 appSecret

4. 项目安装方式

4.1 创建包绑定

使用以下命令创建包绑定:

wsk package bind /whisk.system/pushnotifications myPush -p appId myAppID -p appSecret myAppSecret

4.2 验证包绑定

使用以下命令验证包绑定是否存在:

wsk package list

输出应包含类似以下内容:

packages
/myNamespace/myPush private binding

通过以上步骤,您可以成功安装并使用 Push 包来发送推送通知和管理设备活动事件。

登录后查看全文
热门项目推荐