1、配置说明
IOS 修改PushConfig.plist文件,将“极光APPKey”替换为你在极光推送官网申请的“APPKey”。
Android 修改AndroidManifest.xml文件,将内容中“包名”替换为自己应用包名,将“极光APPKey”替换为你在极光推送官网申请的“APPKey”。
说明:请确保你在APICloud和JPush中的应用包名(IOS和Android)保持一致,否则不能正常使用推送模块。
1、演示代码 <script type="text/javascript">
/*IOS和Android通用功能*/ var jpush=null; apiready = function(){ jpush = api.require('eis.jpush'); //初始化 jpush.init(function(ret){ api.toast({ msg: "init:"+ret.status, duration:2000, location: 'top' }); }); //监听推送消息 jpush.setListener(function(ret){ //推送消息:{msg:"内容", action:"点击消息后的操作", msgid:"极光推送消息Id" +(接收到的原始消息)} alert("msg:"+ret.msg+" action:"+ret.action+" msgid:"+ret.msgid); }); };
//获取设备的RegistrationID,设备的唯一标识 function getRegistrationID(){ //返回结果{status:true, registrationID:"注册Id"} jpush.getRegistrationID(callBack); }
//设置设备标签 function setTags(){ //返回结果{status:true, resultCode:"记录号", tags:"标签名"} jpush.setTags({tags:"testTags1,testTags2"}, callBack); }
//设置设备别名 function setAlias(){ //返回结果{status:true, resultCode:"记录号", alias:"别名"} jpush.setAlias({alias:"testAlias1"}, callBack); }
//设置设备标签和别名 function setTagsWithAlias(){ //返回结果{status:true, resultCode:"记录号", tags:"标签名", alias:"别名"} jpush.setTagsWithAlias({tags:"testTags3,testTags4",alias:"testAlias2"}, callBack); }
//设置调试模式 function setDebugMode(){ //IOS jpush.setDebugMode(callBack); //Android //debugMode:true 启用调试模式,false 停用调试模式 //jpush.setDebugMode({debugMode:true},callBack); }
/*IOS特有功能*/
function startLogPageView(){ jpush.startLogPageView({pageName:"logPage"}, callBack); }
function stopLogPageView(){ jpush.stopLogPageView({pageName:"logPage"}, callBack); }
function setLogOFF(){ jpush.setLogOFF(callBack); }
//设置APP角标 function setBadge(){ jpush.setBadge({badge:5}, callBack); }
//清空APP角标 function resetBadge(){ jpush.resetBadge(callBack); }
/*Android特有功能*/
//停止接收推送消息 function stopPush(){ jpush.stopPush(function(ret){ if(ret){ alert("stopPush:"+ret.status); } }); }
//恢复接收推送消息 function resumePush(){ jpush.resumePush(function(ret){ if(ret){ alert("resumePush:"+ret.status); } }); }
//判断是否已停止接收推送消息 function isPushStopped(){ jpush.isPushStopped(function(ret){ if(ret.status){ alert("isPushStopped:"+ret.isStopped); } }); }
//设置最后的推送通知数量 function setLatestNotificationNum(){ jpush.setLatestNotificationNum({num:5},function(ret){ if(ret){ alert("setLatestNotificationNum:"+ret.status); } }); }
//设置接收推送消息时段 function setPushTime(){ //dayArray:星期一到星期日 //startHour:开始时段(24小时制) //endHour:接收时段(24小时制) jpush.setPushTime({dayArray:[1,2,3,4,5] , startHour:0 , endHour:23},function(ret){ if(ret){ alert("setPushTime:"+ret.status); } }); } //清空通知栏全部推送消息 function clearAllNotification(){ jpush.clearAllNotification(function(ret){ if(ret){ alert("clearAllNotification:"+ret.status); } }); }
//删除通知栏指定推送消息 function clearNotificationById(){ jpush.clearNotificationById({notificationId:1},function(ret){ if(ret){ alert("clearNotificationById:"+ret.status); } }); }
/*原生代码交互完成后的回调方法,可根据自己的需求自定义*/ function callBack(ret, err){ if (ret) { api.toast({ msg: "return:"+ret.status, duration:2000, location: 'top' }); } } </script>
模块下载
|