cordova+H5,集成极光推送

集成极光推送

插件:jpush-phonegap-plugin

github地址

API地址

一般写法

document.addEventListener("deviceready", function () {
     
	onDeviceReady();
},false);

function onDeviceReady() {
     
    document.addEventListener("jpush.receiveRegistrationId", function (event) {
     
    }, false)
    window.JPush ? initiateUI() : '';
};

function getRegistrationID() {
     
    window.JPush.getRegistrationID(onGetRegistrationID);
}
function onGetRegistrationID(data) {
     
    // alert('RegistrationID is'+data)
    if (data.length == 0) {
     
        var t1 = window.setTimeout(getRegistrationID, 1000);
    }
};

function onOpenNotification(event) {
     
    var alertContent;
    if (device.platform == "Android") {
     
        alertContent = event.alert;
    } else {
     
        alertContent = event.aps.alert;
        // alert('onOpenNotification'+event.aps.badge)
        // window.plugins.jPushPlugin.setBadge(event.aps.badge-1);
        // window.plugins.jPushPlugin.resetBadge();
        // window.plugins.jPushPlugin.setApplicationIconBadgeNumber(event.aps.badge-1);
        // alert(window.plugins.jPushPlugin.getApplicationIconBadgeNumber())
    }
    // person.$router.push('/main');
};

function onReceiveNotification(event) {
     
    var alertContent;
    if (device.platform == "Android") {
     
        alertContent = event.alert;
    } else {
     
        alertContent = event.aps.alert;
        // alert('onReceiveNotification'+event.aps.badge)
    }
};
function initiateUI() {
     
    window.JPush.init();
    window.JPush.resumePush();//恢复推送
    window.JPush.setDebugMode(true);
    window.setTimeout(getRegistrationID, 1000);
    // if (device.platform != "Android") {
     
    //     window.JPush.setApplicationIconBadgeNumber(0);
    // }
};

document.addEventListener("jpush.openNotification", onOpenNotification, false);
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);

针对性的推送消息

需要设置别名或者标签
设置标签,为用户的cid

/* 设置推送标签 */
 window.JPush ? window.JPush.setAlias({ sequence: 1, alias: cid }) : '';

你可能感兴趣的:(APP与H5,cordova+h5,极光推送)