66 lines
2.5 KiB
JavaScript
66 lines
2.5 KiB
JavaScript
/**
|
|
* 推送处理业务逻辑
|
|
* yinjihuan
|
|
*/
|
|
document.addEventListener("plusready", function() {
|
|
message = document.getElementById("message");
|
|
// 监听点击消息事件
|
|
plus.push.addEventListener("click", function(msg) {
|
|
// 判断是从本地创建还是离线推送的消息
|
|
var payload = msg.payload;
|
|
var title = msg.title;
|
|
var content = msg.content;
|
|
switch(payload) {
|
|
case "LocalMSG":
|
|
alert("点击本地创建消息启动:");
|
|
break;
|
|
default:
|
|
if (plus.os.name == "Android"){
|
|
payload = JSON.parse(payload);
|
|
if (payload.type == "0") {
|
|
plus.ui.alert(title+"\n"+content);
|
|
} else if (payload.type == "1") {
|
|
plus.ui.alert(title+"\n"+content,function(){
|
|
window.location.href = payload.url;
|
|
});
|
|
} else if (payload.type == "2") {
|
|
plus.ui.alert(title+"\n"+content,function(){
|
|
openUrl(basePath+'/message/openView?url='+payload.url);
|
|
});
|
|
}
|
|
} else {
|
|
if (payload.type == "0") {
|
|
plus.ui.alert(content);
|
|
} else if (payload.type == "1") {
|
|
plus.ui.alert(content,function(){
|
|
window.location.href = payload.url;
|
|
});
|
|
} else if (payload.type == "2") {
|
|
plus.ui.alert(content,function(){
|
|
openUrl(basePath+'/message/openView?url='+payload.url);
|
|
});
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
}, false);
|
|
|
|
// 监听在线消息事件, iOS透传消息在线时会进入这里进行处理
|
|
plus.push.addEventListener("receive", function(msg) {
|
|
var title = msg.title;
|
|
var content = msg.content;
|
|
var payload = msg.payload;
|
|
if (payload.type == "0") {
|
|
plus.ui.alert(title+"\n"+content);
|
|
} else if (payload.type == "1") {
|
|
plus.ui.alert(title+"\n"+content,function(){
|
|
window.location.href = payload.url;
|
|
});
|
|
} else if (payload.type == "2") {
|
|
plus.ui.alert(title+"\n"+content,function(){
|
|
openUrl(basePath+'/message/openView?url='+payload.url);
|
|
});
|
|
}
|
|
}, false);
|
|
}, false); |