npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cordova-ohos/cordova-plugin-huawei-push

v1.0.3

Published

Cordova Huawei Push Plugin

Readme

cordova-plugin-huawei-push

zh-CN en

本项目基于 [email protected] 开发,本文档重点阐述其在 OpenHarmony(OHOS)系统中的具体应用。

简介

cordova-plugin-huawei-push 是 Harmony Cordova 生态系统中一款核心插件,用于在 Cordova/Ionic 混合移动应用中集成 Huawei Push Kit(华为推送服务)的官方插件。它允许应用接收来自华为服务器的通知消息,从而在华为设备上实现推送功能,此插件的使用需要后台服务端的配合。

支持平台

  • Android:API 19 及以上(Android 4.4+)

  • iOS:10.0 及以上

  • OHOS:5.0+

下载安装

通过 hcordova CLI 即可快速安装插件,支持从 npm 仓库或 GitCode 仓库获取。

从 npm 安装(推荐)

# 使用 hcordova CLI 安装
# 安装 hcordova 命令化工具
npm install -g hcordova
# 全平台安装插件
hcordova plugin add cordova-plugin-huawei-push
# 安装指定版本
hcordova plugin add [email protected]

指定平台安装 ohos

仅为 OHOS 平台安装插件:

# 仅安装到 OHOS 平台
hcordova plugin add cordova-plugin-huawei-push --platform ohos
# 安装指定版本并指定 OHOS 平台
hcordova plugin add [email protected] --platform ohos

从 GitCode 仓库安装

仅为 OHOS 平台安装插件:

# 仅安装到 OHOS 平台
# 默认分支安装
hcordova plugin add https://gitcode.com/CPF-Cordova/cordova-plugin-huawei-push.git --platform ohos

# 指定标签/分支安装
hcordova plugin add https://gitcode.com/CPF-Cordova/cordova-plugin-huawei-push.git@develop --platform ohos

离线安装(本地包)

适用于无网络环境,先下载插件包到本地,再执行离线安装:

# 下载插件包到本地(示例路径:~/Downloads/cordova-plugin-huawei-push)
# 执行离线安装
hcordova plugin add ~/Downloads/cordova-plugin-huawei-push --platform ohos

安装后验证

安装完成后,可通过以下命令验证插件是否成功添加到项目中:

# 查看已安装的插件列表,若包含本插件 ID 则表示插件已成功安装
hcordova plugin list

卸载

# Cordova CLI 全平台卸载
hcordova plugin remove cordova-plugin-huawei-push 
# 指定平台卸载
hcordova plugin remove cordova-plugin-huawei-push --platform ohos

约束与限制

  1. 依赖后台服务端配合,插件仅负责客户端接收推送消息,需服务端配合调用华为推送接口发送消息;
  2. 使用前需在华为开发者联盟创建应用并启用 Push Kit 服务,完成相关配置;
  3. 主要适配华为设备,非华为设备可能无法正常使用推送功能。

兼容性

支持:

| 项目 | 版本/信息 | |-----|--------| | SDK | API12+ | | IDE | DevEco Studio: 5.0+ | | ROM | 5.1+ | | Emulator | OpenHarmony 6.0+ |

在以下版本中已测试通过:

| 项目 | 版本/信息 | |-----|--------| | @cordova-ohos/ohos | 14.0.1-ohos-14.0.1 | | SDK | 5.0.0(12) | | IDE | DevEco Studio: 6.0.13.200 | | ROM | 5.1.0.120 SP3 | | Emulator | OpenHarmony 6.0.1(21) |

使用示例

OpenHarmony 配置

修改项目中的 EntryAbility 的代码,添加推送插件在 ArkTS 侧监听和初始化:

export default class EntryAbility extends UIAbility {
   onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
      pagePushNotify(want.parameters); // 点击通知消息传送数据给 cordova
   }

   onNewWant(want: Want): void {
      pagePushNotify(want.parameters); // 点击通知消息传送数据给 cordova
   }
}

注册 OpenHarmony 推送服务

注册成功后,返回 token,将 token 发送到服务器后端,发送推送消息时需要。

huaweiPush.register(function(token) {
    console.log("huaweitoken:" + token);
}, function(err) {
    console.log(err);
}, []);

监听收到推送通知

应用在前台时,收到通知通知到 JS 侧,如果应用不在活跃状态,应用激活后,会收到通知

document.addEventListener("huaweiMessageReceived", function(content){
    console.log(content);
}, false);

返回 content 的,不同的通知,内容不同 点击查看华为推送说明

使用说明

前置条件

  1. 访问 华为开发者联盟

  2. 创建新应用或选择现有应用

  3. 启用 Push Kit 服务

  4. 根据华为的文档配置开通 push 服务

配置参数

无额外配置参数,需提前在华为开发者联盟完成应用及 Push Kit 服务配置,确保插件正常调用华为推送接口。

新增特性

  1. 适配 OHOS 5.0+ 系统,严格遵循 OpenHarmony 开发规范及华为 Push Kit 服务要求;

  2. 完善 ArkTS 侧初始化配置,支持通知消息点击数据传递;

  3. 提供简洁的 API 接口,支持推送服务注册及消息监听,适配 Cordova 应用开发场景;

  4. 兼容华为设备特性,解决无 Google Mobile Services 设备的推送需求。

目录结构

cordova-plugin-huawei-push/
├── src/                          # 源代码目录
│   └── main/                     # 主要源代码
│       ├── cpp/                  # C++ 原生代码
│       │   └── HuaweiPush/       # 华为推送模块
│       │       ├── HuaweiPush.cpp  # 华为推送功能的 C++ 实现
│       │       └── HuaweiPush.h    # 华为推送功能的头文件
│       └── ets/                  # ArkTS 代码(OpenHarmony API)
│           └── components/       # 组件目录
│               └── PluginAction/ # 插件动作组件
│                   └── getPushToken.ets  # 获取推送令牌的 ArkTS 实现
├── www/                          # Web 资源目录
│   └── huawei-push.js            # JavaScript 华为推送接口(Cordova 桥接层)
├── d.sh                          # 构建脚本
├── .gitignore                    # Git 忽略文件配置
├── LICENSE                       # 项目开源许可证
├── OAT.xml                       # OpenHarmony 审核配置文件
├── package.json                  # Node.js 包配置
├── plugin.xml                    # Cordova 插件描述文件(核心配置)
└── README.md                     # 项目说明文档

贡献代码

使用过程中发现任何问题都可以提 Issue ,当然也非常欢迎发 PR 共建。

许可证

本插件基于 Apache License 2.0 开源,详见 LICENSE 文件。

官方资源

OHOS Cordova:https://gitcode.com/CPF-Cordova/cordova-plugin-huawei-push

Android/iOS:https://npmjs.com/cordova-plugin-huawei-push