phonegap+激光推送做ios的消息推送
*光推送插件地址:https://github.com/jpush/jpush-phonegap-plugin
1.cordova,git 环境
2.过程遇到的错误
将这个包再次导入
修改一处地方
字典里appkey的修改
3.
登陆并加标注
var onDeviceReady = function(){
console.log(“JPushPlugin:Device ready!”);
initiateUI();
}
var initiateUI = function(){
try{
window.plugins.jPushPlugin.init();
if(device.platform != “Android”){
window.plugins.jPushPlugin.setBadge(0);//服务器角标清0
window.plugins.jPushPlugin.setDebugModeFromIos();
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);//角标
}else{
window.plugins.jPushPlugin.setDebugMode(true);
}
var alias=userName;
window.plugins.jPushPlugin.setAlias(alias);
}catch(exception){
console.log(exception);
}
}
document.addEventListener(“deviceready”, onDeviceReady, false);//初始化设备
4.公用函数的加载
//检索是否session过期
function checkSession(){
try{
$.post(conn+”ds=DS_EASYJOINT_MOBIL_GROUP_LIST”,{},function(data){
var nowHref=window.location.href;
if((data.indexOf(“html”)>-1) && nowHref.indexOf(“login.html”)==-1){
window.location.href=”login.html”;
}
});
}catch(e){
console.log(“checkSession:”+e);
}
}
//推送函数
//window.plugins.jPushPlugin.resumePush(callback)
//var onCallback = function(data) {
// if(data>0){
// //开启
// }else{
// //关闭
// }
//}
function pushMessage(){
var openNotification = function(event){
try{
window.plugins.jPushPlugin.setBadge(0);//服务器角标清0
window.plugins.jPushPlugin.setDebugModeFromIos();
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
checkSession();//过期
}
catch(exception){
console.log(“jpush.openNotification”+exception);
}
}
function onDeviceReadyPush() {
document.addEventListener(“resume”, onResume, false);
window.plugins.jPushPlugin.init();
}
// 处理resume事件
function onResume() {
try{
window.plugins.jPushPlugin.setBadge(0);//服务器角标清0
window.plugins.jPushPlugin.setDebugModeFromIos();
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);//角标
checkSession();//过期
}
catch(exception){
console.log(exception);
}
}
document.addEventListener(“deviceready”, onDeviceReadyPush, false);
document.addEventListener(“jpush.openNotification”, openNotification, false);
}
$(function(){
pushMessage();//推送
});