cordova + vue + 极光推送 实现App推送

jpush-phonegap-plugin的android文档

https://github.com/jpush/jpush-phonegap-plugin/blob/master/doc/Android_detail_api.md

jpush-phonegap-plugin的ios文档

https://github.com/jpush/jpush-phonegap-plugin/blob/master/doc/iOS_API.md

jpush-phonegap-plugin的通用文档文档

https://github.com/jpush/jpush-phonegap-plugin/blob/master/doc/Common_detail_api.md


在极光官网注册用户并创建应用

在项目中添加极光插件:cordova plugin add jpush-phonegap-plugin --variable APP_KEY=3f28b2abffc7a533a0421283

修改vue/src/main.js

function initiateUI() {

  try {

    window.JPush.setDebugMode(true);

    window.JPush.init();

    window.setTimeout(getRegistrationID, 10000);

    if (device.platform != "Android") {

      window.JPush.setApplicationIconBadgeNumber(0);

    }

  } catch (exception) {

    alert("An exception has been occured when init JPush plugin." + exception);

  }

}

function getRegistrationID() {

  window.JPush.getRegistrationID(onGetRegistrationID);

}

function onGetRegistrationID(data) {

  try {

    if (data.length === 0) {

      alert("id is null");

      window.setTimeout(getRegistrationID, 5000);

    } else {

      alert(data);

    }

  } catch (exception) {

    console.log(exception);

  }

}

async function render() {

  await setLocale();

  new Vue({

    router,

    store: store,

    i18n,

    render: h => h(App)

  }).$mount("#app");

}

if (process.env.NODE_ENV === "production") {  document.addEventListener(

    "deviceready",

    function() {

      console.log("device ready");

      render();

      document.addEventListener(

        "jpush.receiveRegistrationId",

        function(event) {

          alert("receiveRegistrationId" + JSON.stringify(event));

        },

        false

      );

      initiateUI();

    },

    false

  );

} else {

  render();

}

亲测android有效

你可能感兴趣的:(cordova + vue + 极光推送 实现App推送)