Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cordova-plugin-mixpush

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cordova-plugin-mixpush

cordova mipush xiaomi

  • 1.0.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

cordova-plugin-mixPush

Cordova 推送,支持设置角标,事件回调。 此项目代码设计以混合推送为基础,兼容多种推送引擎。

注意:此插件的依赖的组件来自mvn仓库,所以需要翻墙。

JAVA SDK 需要1.7版本低于1.7会编译switch语法错误(环境变量是JDK1.7不一定build时候是1.7请查看build.gradle文件下的sourceCompatibility targetCompatibility)。

此项目运用于我公司商业项目上,功能都没问题,我不太会写文档,如有技术问题可邮件询问:qq3451927565

如何使用?

1.请先去小米官网注册推送账号:https://dev.mi.com/console/appservice/push.html

 cordova plugin add cordova-plugin-mixpush --variable ANDROID_PACKAGE_NAME=你的安卓项目包名  --variable MI_PUSH_APP_IOS_ID=你IOS推送id --variable MI_PUSH_APP_IOS_KEY=你的IOS推送Key

Example

code:

   //此代码为最简单用法,详细使用API,请参考www目录下的MixPushPlugin.js 注释
   document.addEventListener('deviceready',push , false);
   function push(){
        var deviceBrand="xiaoMi";//目前只支持小米引擎
        window.plugins.MixPushPlugin.setPushEngine([deviceBrand]);
        var miId = '2882303******08931'; //android id
        var miKey = '57117***2931'; //android key
        //开始启动注册小米推送
        window.plugins.MixPushPlugin.registerPush([miId, miKey]);

        //registerPush事件
       document.addEventListener("MixPushPlugin.onRegisterPush", function onCallBack(data) {
            if (data&&data.code == 200 ) {
                console.log('注册成功:' + data.regId);
                setAlias("qq112");//注册成功就设置Alias
            }else{
                console.log('注册失败:');
            }
        }, false);

        //设置Alias
        function setAlias(alias) {
            window.plugins.MixPushPlugin.setAlias([alias]);
            //onSetAliasPush事件
            document.addEventListener("MixPushPlugin.onSetAliasPush", function onCallBack(data)  {
                if (data) {
                    data.code == 200 ? "" : setAlias(data.alias);
                    console.log("MixPushPlugin.onSetAliasPush" + data.alias);
                }
            }, false);
        }

        //来消息后的事件监听
        document.addEventListener("MixPushPlugin.onNotificationArrived",function onCallBack(data) {
                if (data && data.title) {
                    window.plugins.MixPushPlugin.badgerApplyCount([20]);//来消息后把APP图标上的角标数字改成20
                    console.log('来消息了:' + data.title);
                    alert(data.title);
                }
         }, false);

        //点消息后的事件监听
         document.addEventListener("MixPushPlugin.onNotificationClicked", function onCallBack(data) {
                     if (data && data.title) {
                         window.plugins.MixPushPlugin.badgerApplyCount([0]);//点消息后清空数字
                         console.log('点消息了:' + data.title);
                         alert(data.title);
                     }
         }, false);

   }

IOS注意点

配置MiSDKRun :https://dev.mi.com/doc/?p=2995#d5e70 (如果是测试证书测试环境请配置为Debug)

XCODE推送开关:Xcode中的Capabilities中的Push Notifications打开

当APP处于后台后如何设置角标

当APP被用户按了home键处在后台时,JS可能是停止执行的,那来了消息如何设置角标,只需要让后端大兄弟在推送时角标数即可

android

new Message.Builder()
.extra("unrecv", "" + unrecv) //unrecv int类型的值

ios

new Message.IOSBuilder()
.badge(unrecv)//unrecv int类型的值

Keywords

FAQs

Package last updated on 20 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc