(若想使用该插件,可联系刺鸟)
*推送相关的代码 必须写在root窗口中
由于极光推送插件的IOS和android实现方式不一样,导致部分API不相同,如果是双平台的应用,需要自行判断。
JPUSH服务端SDK,可以直接用程序来触发推送:http://docs.jpush.cn/display/dev/Server-SDKs
Android版示例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body style="background:#fff;">
<div onclick="uexJPush.setTag('a,b,c')">设置标签()</div>
<div onclick="uexJPush.setAlia('ciniao')">设置别名()</div>
<div onclick="uexJPush.clearAllNotifications()">清空所有通知()</div>
<script>
window.uexOnload = function(type){
if (!type){
uexJPush.cbGetPushInfo = function(a,b,c){
/*
c的格式为:{"title":"标题","content":"内容","extra":"自定义数据","notifyid":12312,"apprun":1}
其中:
notifyid为推送ID,如果需要手动清除指定的通知,可使用:
uexJPush.clearNotificationById(notifyid)
apprun为APP状态,若APP启动时候收到的推送,则apprun=1,否则apprun=0
*/
alert('cbGetPushInfo=' + c);
};
uexJPush.cbSetTag = function(a,b,c){
//返回0表示成功,其他表示失败,含义见:
//http://docs.jpush.cn/pages/viewpage.action?pageId=557241
alert('cbSetTag='+c);
};
uexJPush.cbSetAlia = function(a,b,c){
//返回0表示成功,其他表示失败,含义见:
//http://docs.jpush.cn/pages/viewpage.action?pageId=557241
alert('cbSetAlia='+c);
};
uexJPush.registrationCode('你的激活码');
uexJPush.getPushInfo();
uexJPush.setDeviceToken('');
//推送的统计
uexWidget.onSuspend = function(){
uexJPush.onPause();
};
uexWidget.onResume = function(){
uexJPush.onResume();
};
//uexJPush.setPushStatus(0); 不接收所有推送
//uexJPush.setPushStatus(1); 恢复接收所有推送
/*
uexJPush.cbGetPushStatus = function(a,b,c){
//当前是否接收推送 1||0
alert(c);
};
uexJPush.getPushStatus();
*/
}
};
</script>
</body>
</html>IOS示例
<!DOCTYPE HTML>
<html>
<head>
<title>推送测试</title>
<script>
function startPush(){
uexDevice.cbGetInfo = function(opId,dataType, data){
var device = eval('('+data+')');
//获取deviceToken
var deviceToken = device.deviceToken;
if(deviceToken){
alert("devictToken 111="+deviceToken);
uexJPush.setDeviceToken(deviceToken);
}
}
uexJPush.registrationCode('你的激活码');
//设置是否接受推送
uexJPush.setPushStatus('1');
//获取deviceToken
uexDevice.getInfo('11');
}
window.uexOnload = function(type){
uexJPush.cbGetPushStatus=function(opId,dataType,data){
alert("push cbGetPushStatus ="+data);
}
uexJPush.cbSetTag= function(opId,dataType,data){
alert("jpush cbSetTag="+data);
}
uexJPush.cbSetAlia= function(opId,dataType,data){
alert("jpush cbSetAlia="+data);
}
uexJPush.cbGetPushInfo=function(opId,dataType,data){
alert("推送消息格式为:"+data);
}
startPush();
uexWidget.onResume = function(){
startPush();
};
}
function setTags(){
uexJPush.setTag("xuleilei,gaomin,xiaoxi");
}
function setPush(a){
uexJPush.setPushStatus(a);
uexJPush.getPushStatus();
}
</script>
</head>
<body>
<div class="tit">极光推送功能</div>
<div class="conbor">
<div class="consj">
<span>1.获取deviceToken</span>
<input class="btn" type="button" value="绑定token" onclick="uexDevice.getInfo('11');">
<span>2.解绑定推送</span>
<input class="btn" type="button" value="解绑" onclick="setPush(0);">
<span>3.绑定推送</span>
<input class="btn" type="button" value="绑定" onclick="setPush(1);">
<span>4.设置昵称</span>
<input id="uexBAEPush.setAlia"type="text" class="textbox" value="xuleilei">
<input class="btn" type="button" value="设置" onclick="uexJPush.setAlia('hi');">
<span>5.设置tag</span>
<input id="uexBAEPush.setTag"type="text" class="textbox" value="xuleilei">
<input class="btn" type="button" value="设置" onclick="setTags();">
<input class="btn" type="button" value="返回" onclick="uexWindow.back();">
</div>
</div>
</body>
</html>