{"_id":"@capacitor-ohos/push-notifications","_rev":"2-47e55ccd5f5af8545309097d3bd1c1f6","name":"@capacitor-ohos/push-notifications","dist-tags":{"latest":"8.0.2"},"versions":{"8.0.1":{"name":"@capacitor-ohos/push-notifications","version":"8.0.1","keywords":["capacitor","plugin","native"],"author":{"url":"Group","name":"Huawei Device Co., Ltd and iSoftStone Information Technology"},"license":"MIT","_id":"@capacitor-ohos/push-notifications@8.0.1","maintainers":[{"name":"luqi_tan","email":"295099422@qq.com"}],"bugs":{"url":"https://gitcode.com/CPF-Ionic/capacitor-push-notifications/issues"},"dist":{"shasum":"ccdaf307fcf4107816642ec41ac5cce193eb24ec","tarball":"https://registry.npmjs.org/@capacitor-ohos/push-notifications/-/push-notifications-8.0.1.tgz","fileCount":10,"integrity":"sha512-ohFOjdXtXLzr4taBTyPKGbT0EDcphV660rHDugKKykIdIOW9mV7F66H+2vefHYSzjPpS/PTxbymzchIOASFBzA==","signatures":[{"sig":"MEYCIQCgzoYZYI/4rP6hla0BkdR5gFY+8AoCLEDQXHkqoi9GngIhAOjrE1xDBv07oLjxY6sp8wNLWkGXngtR+uigbLO6Zwr0","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":46371},"gitHead":"8f323d9456e5d43b3ed38387a1a6df51ad5b6744","_npmUser":{"name":"luqi_tan","email":"295099422@qq.com"},"capacitor":{"id":"@capacitor/push-notifications","platforms":["openharmony"]},"repository":{"url":"gitcode:CPF-Ionic/capacitor-push-notifications","type":"git"},"_npmVersion":"10.5.1","description":"The Push Notifications API provides access to native push notifications.","directories":{},"_nodeVersion":"22.0.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/push-notifications_8.0.1_1777542380916_0.047042928232591485","host":"s3://npm-registry-packages-npm-production"}},"8.0.2":{"name":"@capacitor-ohos/push-notifications","version":"8.0.2","description":"The Push Notifications API provides access to native push notifications.","capacitor":{"id":"@capacitor/push-notifications","platforms":["openharmony"]},"repository":{"type":"git","url":"gitcode:CPF-Ionic/capacitor-push-notifications"},"bugs":{"url":"https://gitcode.com/CPF-Ionic/capacitor-push-notifications/issues"},"keywords":["capacitor","plugin","native"],"author":{"name":"Huawei Device Co., Ltd and iSoftStone Information Technology","url":"Group"},"license":"MIT","_id":"@capacitor-ohos/push-notifications@8.0.2","gitHead":"b810a1bd27873b6465739d21da4b5374d842c3fe","_nodeVersion":"22.0.0","_npmVersion":"10.5.1","dist":{"integrity":"sha512-Bg062F+/Hqp4rQ1Bkluf/PGNsk2+pM+tqOVsJLSsrAfOAAJfBZnBp5x9vcSAPU2gzs+A1jbqhC35Z3Rh15OpwQ==","shasum":"87fa82692b28f6b8fca3f83e4e957f6461d4f353","tarball":"https://registry.npmjs.org/@capacitor-ohos/push-notifications/-/push-notifications-8.0.2.tgz","fileCount":10,"unpackedSize":47024,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDFJlwrnbpyG1bPmJ2fYMQRfZlIyXY4VRHWcHcMbojUYgIgd8hAIq/Ty3ZAr0EN0B0vPyEwO8s/ITY2WjbvmEppRIs="}]},"_npmUser":{"name":"luqi_tan","email":"295099422@qq.com"},"directories":{},"maintainers":[{"name":"luqi_tan","email":"295099422@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/push-notifications_8.0.2_1784792601809_0.4768136539700636"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-30T09:46:20.784Z","modified":"2026-07-23T07:43:22.173Z","8.0.1":"2026-04-30T09:46:21.049Z","8.0.2":"2026-07-23T07:43:21.950Z"},"bugs":{"url":"https://gitcode.com/CPF-Ionic/capacitor-push-notifications/issues"},"author":{"name":"Huawei Device Co., Ltd and iSoftStone Information Technology","url":"Group"},"license":"MIT","keywords":["capacitor","plugin","native"],"repository":{"type":"git","url":"gitcode:CPF-Ionic/capacitor-push-notifications"},"description":"The Push Notifications API provides access to native push notifications.","maintainers":[{"name":"luqi_tan","email":"295099422@qq.com"}],"readme":"# <center>@capacitor/push-notifications</center>\r\n[![zh-CN](https://img.shields.io/badge/lang-中文-blue.svg)](README.md)\r\n[![en](https://img.shields.io/badge/lang-English-blue.svg)](README.en.md)\r\n\r\n本项目基于 [@capacitor/push-notifications@8.0.0](https://www.npmjs.com/package/@capacitor/push-notifications) 开发。\r\n\r\n## 简介\r\n\r\n`@capacitor/push-notifications` 是 capacitor 生态系统中的核心插件，用于处理应用的推送通知功能，为跨平台应用开发提供设备差异化适配能力，兼容 capacitor 的 Android、iOS 等主流移动平台及浏览器环境，本文档主要说明在 OpenHarmony 系统中的使用。\r\n\r\n该插件支持注册推送通知、获取推送令牌、监听注册事件等功能，帮助开发者快速集成推送通知能力到跨平台应用中。\r\n\r\n## 前置条件\r\n\r\n1. 访问华为开发者联盟网站\r\n2. 创建新应用或选择现有应用\r\n3. 启用 Push Kit（推送服务）\r\n4. 根据文档配置开通相关平台推送服务\r\n\r\n## 支持平台\r\n\r\n- **OpenHarmony**：5.0+\r\n\r\n## 下载安装\r\n\r\n通过命令行或手动引入即可快速安装插件，支持从npm仓库获取。\r\n\r\n### 命令行安装（推荐）\r\n\r\n安装hionic CLI：\r\n\r\n```bash\r\nnpm install -g hionic\r\n```\r\n\r\n以下两种方式中**任选其一**即可，无需重复操作：\r\n\r\nnpm安装：\r\n\r\n```bash\r\n# 安装插件\r\nnpm install @capacitor/push-notifications\r\n\r\n# 同步插件\r\nhionic sync openharmony\r\n```\r\n\r\nhionic CLI安装：\r\n\r\n```bash\r\nhionic plugin add @capacitor/push-notifications\r\n```\r\n\r\n### 手动引入安装\r\n\r\n根据插件源码中 `plugin.xml` 配置在项目中引入插件：\r\n\r\n#### 1. 添加插件配置\r\n\r\n根据 `plugin.xml` 的 `config-json` 项，通过 `target` 字段找到 `entry` 模块中 `capacitor.plugins.json` 文件，并根据 `param` 标签添加配置如下：\r\n\r\n```json\r\n{\r\n   \"pkg\": \"@capacitor/push-notifications\",\r\n   \"classpath\": \"PushNotifications\"\r\n}\r\n```\r\n\r\n#### 2. 修改 CMake 配置\r\n\r\n根据 `plugin.xml` 的 `CMakeLists` 项，通过 `modules-name` 字段找到模块 capacitor，路径为 `target` 字段的 `CMakeLists.txt` 文件，并根据 `param` 标签添加 `add_subdirectory` 和 `target_link_libraries` 如下：\r\n\r\n```cmake\r\n#START_ADD_SUBDIRECTORY\r\n// ...\r\nadd_subdirectory(PushNotifications)\r\n// ...\r\n#END_ADD_SUBDIRECTORY\r\n\r\n// ...\r\n\r\ntarget_link_libraries(capacitor PUBLIC\r\n  \"-Wl,--whole-archive\"\r\n  // ...\r\n  PushNotifications\r\n  // ...\r\n  \"-Wl,--no-whole-archive\"\r\n)\r\n```\r\n\r\n#### 3. 复制源码文件\r\n\r\n根据 `plugin.xml` 的 `source-file` 项，根据 `src` 字段找到需要复制的文件，并根据 `modules-name` 字段和 `target-dir` 字段找到文件复制的具体模块和目录：\r\n\r\n将源码中 src/main/cpp/PushNotifications 目录下 PushNotifications.h、PushNotifications.cpp、CMakeLists.txt 文件引入到 capacitor 模块中 src/main/cpp/PushNotifications 目录下。\r\n\r\n将源码中 src/main/ets/components/PushNotifications 目录下 PushNotifications.ets 文件引入到 capacitor 模块中 src/main/ets/components/PushNotifications 目录下。\r\n\r\n#### 4. 添加 ArkTS 配置\r\n\r\n在 capacitor 模块的 `build-profile.json5` 文件中，`buildOption/arkOptions/runtimeOnly/sources` 配置项数组中加入步骤 3 中拷贝的 ets 文件路径：\r\n\r\n```json\r\n// ...\r\n\"buildOption\":{\r\n  \"arkOptions\": {\r\n    \"runtimeOnly\": {\r\n      \"sources\": [\r\n        // ...\r\n        \"./src/main/ets/components/PushNotifications/PushNotifications.ets\"\r\n        // ...\r\n      ]\r\n    }\r\n  }\r\n}\r\n// ...\r\n```\r\n\r\n## 卸载\r\n\r\n```bash\r\n# 卸载 push-notifications 插件\r\nhionic plugin remove @capacitor/push-notifications\r\n```\r\n\r\n## 约束与限制\r\n\r\n### 兼容性\r\n\r\n在以下版本中已测试通过：\r\n\r\n1. SDK: 5.0.5(17); IDE: DevEco Studio: 6.0.0; ROM: 5.1.0.150;\r\n\r\n## 使用示例\r\n\r\n### 基础示例：权限校验、授权、注册、监听注册、注销\r\n\r\n```javascript\r\nimport { PushNotifications } from '@capacitor/push-notifications';\r\n\r\n// 添加推送事件监听器\r\nconst addListeners = async () => {\r\n  await PushNotifications.addListener('registration', token => {\r\n    console.info('Registration token: ', token.value);\r\n  });\r\n\r\n  await PushNotifications.addListener('registrationError', err => {\r\n    console.error('Registration error: ', err.error);\r\n  });\r\n}\r\n\r\n// 注册推送通知\r\nconst registerNotifications = async () => {\r\n  let permStatus = await PushNotifications.checkPermissions();\r\n\r\n  if (permStatus.receive === 'denied') {\r\n    permStatus = await PushNotifications.requestPermissions();\r\n  }\r\n\r\n  if (permStatus.receive !== 'granted') {\r\n    throw new Error('User denied permissions!');\r\n  }\r\n\r\n  await PushNotifications.register();\r\n}\r\n\r\n// 注销推送通知\r\nawait PushNotifications.unregister();\r\n```\r\n\r\n## 使用说明\r\n\r\n### 接口方法\r\n\r\n| 方法名 | 返回类型 | 描述 |\r\n| ---- | ---- | ---- |\r\n| register() | Promise&lt;void&gt; | 注册应用以接收推送通知，会触发 `registration` 或 `registrationError` 事件 |\r\n| unregister() | Promise&lt;void&gt; | 取消注册应用的推送通知 |\r\n| getDeliveredNotifications() | Promise&lt;[DeliveredNotifications](#deliverednotifications)&gt; | 获取通知屏幕上可见的通知列表，**暂不支持** |\r\n| removeDeliveredNotifications(delivered: [DeliveredNotifications](#deliverednotifications)) | Promise&lt;void&gt; | 从通知屏幕上移除指定的通知，**暂不支持** |\r\n| removeAllDeliveredNotifications() | Promise&lt;void&gt; | 从通知屏幕上移除所有通知，**暂不支持** |\r\n| createChannel(channel: [Channel](#channel)) | Promise&lt;void&gt; | 创建通知渠道，**暂不支持** |\r\n| deleteChannel(args: { id: string }) | Promise&lt;void&gt; | 删除通知渠道，**暂不支持** |\r\n| listChannels() | Promise&lt;[ListChannelsResult](#listchannelsresult)&gt; | 列出可用的通知渠道，**暂不支持** |\r\n| checkPermissions() | Promise&lt;[PermissionStatus](#permissionstatus)&gt; | 检查接收推送通知的权限状态 |\r\n| requestPermissions() | Promise&lt;[PermissionStatus](#permissionstatus)&gt; | 请求接收推送通知的权限 |\r\n| addListener('registration', listenerFunc) | Promise&lt;[PluginListenerHandle](#PluginListenerHandle)&gt; | 监听推送通知注册成功事件，获取推送令牌 |\r\n| addListener('registrationError', listenerFunc) | Promise&lt;[PluginListenerHandle](#PluginListenerHandle)&gt; | 监听推送通知注册失败事件，获取错误信息 |\r\n| addListener('pushNotificationReceived', listenerFunc) | Promise&lt;[PluginListenerHandle](#PluginListenerHandle)&gt; | 监听设备接收到推送通知的事件，**暂不支持** |\r\n| addListener('pushNotificationActionPerformed', listenerFunc) | Promise&lt;[PluginListenerHandle](#PluginListenerHandle)&gt; | 监听用户对推送通知执行操作的事件，**暂不支持** |\r\n| removeAllListeners() | Promise&lt;void&gt; | 移除该插件的所有原生监听器 |\r\n\r\n### 数据结构\r\n\r\n#### PermissionStatus\r\n\r\n| 属性 | 类型 | 描述 |\r\n| --- | --- | --- |\r\n| **`receive`** | [PermissionState](#permissionstate) | 接收通知的权限状态 |\r\n\r\n#### PluginListenerHandle\r\n\r\n| 属性 | 类型 | 描述 |\r\n| --- | --- | --- |\r\n| **`remove`** | () => Promise<void> |  |\r\n\r\n#### PermissionStatus\r\n\r\n| 属性 | 类型 | 描述 |\r\n| --- | --- | --- |\r\n| **receive** | [PermissionState](#permissionstate) | 接收通知的权限状态 |\r\n\r\n#### Token\r\n\r\n| 属性 | 类型 | 描述 |\r\n| --- | --- | --- |\r\n| **value** | string | 在 OpenHarmony 系统上 Push Token 令牌 |\r\n\r\n#### RegistrationError\r\n\r\n| 属性 | 类型 | 描述 |\r\n| --- | --- | --- |\r\n| **error** | string | 描述注册失败的错误信息 |\r\n\r\n#### DeliveredNotifications\r\n\r\n| 属性 | 类型 | 描述 |\r\n| --- | --- | --- |\r\n| **notifications** | [PushNotificationSchema](#pushnotificationschema)[] | 通知屏幕上可见的通知列表 |\r\n\r\n#### Channel\r\n\r\n| 属性 | 类型 | 描述 |\r\n| --- | --- | --- |\r\n| **id** | string | 渠道标识符 |\r\n| **name** | string | 渠道的人类友好名称 |\r\n| **description** | string | 渠道的描述 |\r\n| **sound** | string | 为发布到此渠道的通知播放的声音 |\r\n| **importance** | [Importance](#importance) | 发布到此渠道的通知的中断级别 |\r\n| **visibility** | [Visibility](#visibility) | 发布到此渠道的通知的可见性 |\r\n| **lights** | boolean | 发布到此渠道的通知是否应显示通知灯 |\r\n| **lightColor** | string | 发布到此渠道的通知的灯光颜色 |\r\n| **vibration** | boolean | 发布到此渠道的通知是否应振动 |\r\n\r\n#### ListChannelsResult\r\n\r\n| 属性 | 类型 | 描述 |\r\n| --- | --- | --- |\r\n| **channels** | [Channel](#channel)[] | 应用创建的所有渠道的列表 |\r\n\r\n#### PushNotificationSchema\r\n\r\n| 属性 | 类型 | 描述 |\r\n| --- | --- | --- |\r\n| **title** | string | 通知标题 |\r\n| **subtitle** | string | 通知副标题 |\r\n| **body** | string | 通知的主要文本负载 |\r\n| **id** | string | 通知标识符 |\r\n| **tag** | string | 通知标签 |\r\n| **badge** | number | 应用图标徽章显示的数字 |\r\n| **data** | string | 包含在推送通知负载中的数据 |\r\n| **click_action** | string | 用户打开通知时要执行的操作 |\r\n| **link** | string | 通知中的深层链接 |\r\n| **group** | string | 用于通知分组的组标识符 |\r\n| **groupSummary** | boolean | 指定此通知作为关联 `group` 的摘要 |\r\n\r\n#### ActionPerformed\r\n\r\n| 属性 | 类型 | 描述 |\r\n| --- | --- | --- |\r\n| **actionId** | string | 对通知执行的操作 |\r\n| **inputValue** | string | 在通知操作上输入的文本 |\r\n| **notification** | [PushNotificationSchema](#pushnotificationschema) | 执行操作的通知 |\r\n\r\n#### Importance\r\n\r\n| 值 | 描述 |\r\n| --- | --- |\r\n| `1` | 最低 - 无声音，无弹出 |\r\n| `2` | 低 - 无声音，无弹出 |\r\n| `3` | 默认 - 有声音，无弹出 |\r\n| `4` | 高 - 有声音，有弹出 |\r\n| `5` | 最高 - 有声音，有弹出，屏幕锁定时显示 |\r\n\r\n#### Visibility\r\n\r\n| 值 | 描述 |\r\n| --- | --- |\r\n| `-1` | 秘密 - 通知不会显示在锁定屏幕上 |\r\n| `0` | 私有 - 通知会显示在锁定屏幕上，但敏感内容会被隐藏 |\r\n| `1` | 公共 - 通知会完整显示在锁定屏幕上 |\r\n\r\n## 遗留问题\r\n\r\n以下功能对标源库暂未实现：\r\n- `getDeliveredNotifications` - 获取已投递通知列表\r\n- `removeDeliveredNotifications` - 移除指定通知\r\n- `removeAllDeliveredNotifications` - 移除所有通知\r\n- `createChannel` - 创建通知渠道\r\n- `deleteChannel` - 删除通知渠道\r\n- `listChannels` - 列出通知渠道\r\n- `pushNotificationReceived` - 推送通知接收事件\r\n- `pushNotificationActionPerformed` - 推送通知点击操作事件\r\n\r\n原因：OpenHarmony 推送服务架构差异，相关功能需要平台进一步支持后方可实现。\r\n\r\n## 目录结构\r\n\r\n```\r\n|---- 项目根目录\r\n|     |---- src\r\n|           |---- main\r\n|                 |---- cpp\r\n|                       |---- PushNotifications   # 插件核心 C++ 实现\r\n|                             |---- PushNotifications.cpp\r\n|                             |---- PushNotifications.h\r\n|                             |---- CMakeLists.txt\r\n|                 |---- ets\r\n|                       |---- components\r\n|                             |---- PushNotifications   # ArkTS 组件实现\r\n|                                   |---- PushNotifications.ets\r\n|     |---- README.md                  # 说明文档\r\n|     |---- package.json               # npm 配置文件\r\n|     |---- plugin.xml                 # capacitor 插件配置\r\n|     |---- LICENSE                    # 许可证文件\r\n```\r\n\r\n## 贡献代码\r\n\r\n使用过程中发现任何问题都可以提 [Issue](https://gitcode.com/CPF-Ionic/capacitor-push-notifications/issues)，当然，也非常欢迎发 [PR](https://gitcode.com/CPF-Ionic/capacitor-push-notifications/pulls) 共建。\r\n\r\n## 许可证\r\n\r\n本插件基于 **MIT License** 开源，详见 [LICENSE](./LICENSE) 文件。\r\n","readmeFilename":"README.md"}