https://github.com/waitaction/cordova-plugin-huawei-push
华为推送Cordova插件
https://github.com/waitaction/cordova-plugin-huawei-push
Last synced: 8 months ago
JSON representation
华为推送Cordova插件
- Host: GitHub
- URL: https://github.com/waitaction/cordova-plugin-huawei-push
- Owner: waitaction
- License: apache-2.0
- Created: 2020-09-04T06:25:39.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-04T08:55:38.000Z (over 5 years ago)
- Last Synced: 2025-07-04T10:43:33.083Z (9 months ago)
- Language: Java
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 华为推送
华为手机推送
安装`cordova-plugin-huawei-push`
```
cordova plugin add cordova-plugin-huawei-push
```
## 华为推送配置
在项目根目录建个文件夹 `config-push` ,将 `agconnect-services.json` 拷贝到 `config-push` 目录。
> `agconnect-services.json` 文件,请从华为开发者官网配置推送后下载到本地。
> [华为开发者官网](https://developer.huawei.com/consumer/cn/)
调试推送需要使用签名后的apk,因此建议在 `cordova` 根目录建 `build.json` 文件,把签名信息配置一下
``` json
{
"android": {
"debug": {
"keystore": "./keys/testpush.keystore",
"alias": "testpush.keystore",
"storePassword": "123456",
"password": "123456"
},
"release": {
"keystore": "./keys/testpush.keystore",
"alias": "testpush.keystore",
"storePassword": "123456",
"password": "123456"
}
}
}
```
> `build.json` 的上述配置需要改成你自已的配置信息
如需调试,需要在真实的设备,使用以下命令调试
``` shell
cordova run android --device --buildConfig
```
## 使用
使用前需注册,以获取 `token` ,你可以将 `token` 与你的app用户信息关联后上传到服务器
``` js
// 注册推送
huaweiPush.register(function(token) {
console.log(token);
}, function(err) {
console.log(err);
}, []);
// 接收token
huaweiPush.onNewToken(function(token) {
console.log(token); // 会多次接收到token
});
```
注册完成后,需要监听 `messageReceived` 事件
``` js
document.addEventListener("messageReceived", function(result) {
console.log(result);
}, false);
```