Giter VIP home page Giter VIP logo

cordova-huawei-hms's Introduction

华为推送 HMS SDK,由于华为应用市场审核应用必须使用最新版的hms sdk,为方便区分,插件版本与HMS SDK版本号保持一致。

(注:原作者的插件一年前已停止更新,旧版插件无法通过华为应用市场审核,请使用本分支的插件)

更新于2018年6月28号

cordova-huawei-hms

华为推送cordova插件,目前仅适配安卓手机

安装

cordova plugin add https://github.com/waitaction/cordova-huawei-hms.git --variable APPID=YOURAPPID --variable  PACKAGENAME=YOURPACKAGENAME --variable cpid=YOURCPID

例如cordova plugin add https://github.com/waitaction/cordova-huawei-hms.git --variable APPID=10111111 --variable PACKAGENAME=com.lifang123.www --variable cpid=350841385123

怎么用

初始 hms 连接

cordova.plugins.huaweipush.init();

获取设备token

document.addEventListener('huaweipush.receiveRegisterResult', function (event) {
    console.log(event) // 设备token包含在event对像
}.bind(this), false);

你可以使用 event.token 获取到设备token

停止推送服务

cordova.plugins.huaweipush.stop();

接收到推送通知时,点击通知栏打开应用后会触发下面的事件

document.addEventListener('huaweipush.notificationOpened', function (event) {
    console.log(event) // event包含了你自定义的额外字段的数据
}.bind(this), false)

接收透传通知

document.addEventListener('huaweipush.pushMsgReceived', function (event) {
    console.log(event) // event包含了你自定义的额外字段的数据
}.bind(this), false)

尽早定义事件

document.addEventListener事件要尽早定义,在调用cordova.plugins.huaweipush.init()之前.

    <html>
    <head>...</head>
    <body>
    <script>
        document.addEventListener('huaweipush.receiveRegisterResult', function (event) {
            console.log(event) // 设备token包含在event对像
        }.bind(this), false);
    
        document.addEventListener('huaweipush.notificationOpened', function (event) {
            console.log(event) // event包含了你自定义的额外字段的数据
        }.bind(this), false)
    
        document.addEventListener('huaweipush.pushMsgReceived', function (event) {
            console.log(event) // event包含了你自定义的额外字段的数据
        }.bind(this), false)
    </script>
    <div>内容</div>
    </body>
    </html>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.