jpush-phonegap-plugin/example/index.html

198 lines
7.5 KiB
HTML
Raw Normal View History

2014-01-21 14:15:14 +08:00
<!DOCTYPE html>
<html>
2016-01-21 15:15:48 +08:00
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2016-04-08 18:01:27 +08:00
<title>JPush Phonegap Simple Demo</title>
<link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css" />
2016-01-21 15:15:48 +08:00
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.1.1.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
2016-04-08 18:01:27 +08:00
var onDeviceReady = function() {
2016-01-21 15:15:48 +08:00
console.log("JPushPlugin:Device ready!");
initiateUI();
};
function getRegistrationID() {
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
}
2016-04-08 18:01:27 +08:00
var onGetRegistradionID = function(data) {
2016-01-21 15:15:48 +08:00
try {
console.log("JPushPlugin:registrationID is " + data);
if (data.length == 0) {
var t1 = window.setTimeout(getRegistrationID, 1000);
}
2016-01-21 15:15:48 +08:00
$("#registrationid").html(data);
2016-04-08 18:01:27 +08:00
} catch (exception) {
2016-01-21 15:15:48 +08:00
console.log(exception);
}
};
2016-04-08 18:01:27 +08:00
var onTagsWithAlias = function(event) {
2016-01-21 15:15:48 +08:00
try {
console.log("onTagsWithAlias");
var result = "result code:" + event.resultCode + " ";
result += "tags:" + event.tags + " ";
result += "alias:" + event.alias + " ";
$("#tagAliasResult").html(result);
2016-04-08 18:01:27 +08:00
} catch (exception) {
2016-01-21 15:15:48 +08:00
console.log(exception)
2015-01-27 18:19:16 +08:00
}
2016-01-21 15:15:48 +08:00
};
2016-04-08 18:01:27 +08:00
var onOpenNotification = function(event) {
2016-01-21 15:15:48 +08:00
try {
var alertContent;
if (device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.openNotification.alert;
} else {
alertContent = event.aps.alert;
2015-03-10 16:37:08 +08:00
}
2016-01-21 15:15:48 +08:00
alert("open Notificaiton:" + alertContent);
2016-04-08 18:01:27 +08:00
} catch (exception) {
2016-01-21 15:15:48 +08:00
console.log("JPushPlugin:onOpenNotification" + exception);
}
};
2016-04-08 18:01:27 +08:00
var onReceiveNotification = function(event) {
2016-01-21 15:15:48 +08:00
try {
var alertContent;
if (device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
} else {
alertContent = event.aps.alert;
2015-03-10 16:37:08 +08:00
}
2016-01-21 15:15:48 +08:00
$("#notificationResult").html(alertContent);
2016-04-08 18:01:27 +08:00
} catch (exeption) {
2016-01-21 15:15:48 +08:00
console.log(exception)
2015-03-10 16:37:08 +08:00
}
2016-01-21 15:15:48 +08:00
};
2016-04-08 18:01:27 +08:00
var onReceiveMessage = function(event) {
try {
2016-01-21 15:15:48 +08:00
var message;
if (device.platform == "Android") {
message = window.plugins.jPushPlugin.receiveMessage.message;
} else {
message = event.content;
2014-06-05 16:36:54 +08:00
}
2016-01-21 15:15:48 +08:00
$("#messageResult").html(message);
2016-04-08 18:01:27 +08:00
} catch (exception) {
2016-01-21 15:15:48 +08:00
console.log("JPushPlugin:onReceiveMessage-->" + exception);
}
};
2016-04-08 18:01:27 +08:00
var initiateUI = function() {
2016-01-21 15:15:48 +08:00
try {
window.plugins.jPushPlugin.init();
getRegistrationID();
if (device.platform != "Android") {
window.plugins.jPushPlugin.setDebugModeFromIos();
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
} else {
window.plugins.jPushPlugin.setDebugMode(true);
window.plugins.jPushPlugin.setStatisticsOpen(true);
2014-06-05 16:36:54 +08:00
}
2016-04-08 18:01:27 +08:00
} catch (exception) {
2016-01-21 15:15:48 +08:00
console.log(exception);
}
2016-04-08 18:01:27 +08:00
$("#setTagWithAliasButton").click(function(ev) {
2016-01-21 15:15:48 +08:00
try {
var tag1 = $("#tagText1").attr("value");
var tag2 = $("#tagText2").attr("value");
var tag3 = $("#tagText3").attr("value");
var alias = $("#aliasText").attr("value");
var dd = [];
2016-04-08 18:01:27 +08:00
if (tag1 != "") {
dd.push(tag1);
}
if (tag2 != "") {
dd.push(tag2);
}
2016-04-08 18:01:27 +08:00
if (tag3 != "") {
dd.push(tag3);
2014-06-10 14:14:02 +08:00
}
2016-01-21 15:15:48 +08:00
window.plugins.jPushPlugin.setTagsWithAlias(dd, alias);
2016-04-08 18:01:27 +08:00
} catch (exception) {
2016-01-21 15:15:48 +08:00
console.log(exception);
}
})
};
2016-04-08 18:01:27 +08:00
2016-01-21 15:15:48 +08:00
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("jpush.openNotification", onOpenNotification, false);
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
</script>
</head>
2016-04-08 18:01:27 +08:00
<body>
<div data-role="page" id="page">
<div data-role="content">
<form>
<div class="ui-body ui-body-b">
<div data-role="fieldcontain">
<center>
<h3>JPushPlugin Example</h3>
</center>
<span name="alias" id="alias"></span>
<hr/>
<label>RegistrationID: </label>
<label id="registrationid">null</label>
</div>
<div data-role="fieldcontain">
<label>Tags: </label>
<table>
<tr>
<td>
<input type="text" id="tagText1" />
</td>
</tr>
<tr>
<td>
<input type="text" id="tagText2" />
</td>
</tr>
<tr>
<td>
<input type="text" id="tagText3" />
</td>
</tr>
</table>
<label>Alias: </label>
<table>
<tr>
<td>
<input type="text" id="aliasText" />
</td>
</tr>
</table>
</div>
<div data-role="fieldcontain">
<input type="button" id="setTagWithAliasButton" value="Add tag and alias" />
</div>
<div data-role="fieldcontain">
<label id="tagAliasPrompt">设置tag/alias结果:</label>
<label id="tagAliasResult">null</label>
</div>
<div data-role="fieldcontain">
<label id="notificationPrompt">接受的通知内容:</label>
<label id="notificationResult">null</label>
</div>
<div data-role="fieldcontain">
<label id="messagePrompt">接受的自定义消息:</label>
<label id="messageResult">null</label>
</div>
2016-01-21 15:15:48 +08:00
</div>
2016-04-08 18:01:27 +08:00
</form>
</div>
2016-01-21 15:15:48 +08:00
</div>
</body>
2016-04-08 18:01:27 +08:00
2014-01-21 14:15:14 +08:00
</html>