jpush-phonegap-plugin/example/index.html

262 lines
8.5 KiB
HTML
Raw Normal View History

2014-01-21 14:15:14 +08:00
<!DOCTYPE html>
<html>
2017-09-22 16:06:44 +08:00
<head>
2016-01-21 15:15:48 +08:00
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2017-09-22 16:06:44 +08:00
<title>JPush Phonegap Simple Demo</title>
<link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css" />
<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() {
2017-09-22 16:06:44 +08:00
initiateUI();
2016-01-21 15:15:48 +08:00
};
2017-09-22 16:06:44 +08:00
var getRegistrationID = function() {
2017-09-22 16:06:44 +08:00
window.JPush.getRegistrationID(onGetRegistrationID);
};
2017-09-22 16:06:44 +08:00
2016-04-11 10:01:55 +08:00
var onGetRegistrationID = function(data) {
2017-09-22 16:06:44 +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
}
2017-09-22 16:06:44 +08:00
$("#registrationId").html(data);
} catch (exception) {
console.log(exception);
}
};
2016-04-08 18:01:27 +08:00
var onTagsWithAlias = function(event) {
2017-09-22 16:06:44 +08:00
try {
console.log("onTagsWithAlias");
var result = "result code:" + event.resultCode + " ";
result += "tags:" + event.tags + " ";
result += "alias:" + event.alias + " ";
$("#tagAliasResult").html(result);
} catch (exception) {
console.log(exception)
}
2016-01-21 15:15:48 +08:00
};
2017-09-22 16:06:44 +08:00
2016-04-08 18:01:27 +08:00
var onOpenNotification = function(event) {
2017-09-22 16:06:44 +08:00
try {
var alertContent;
if (device.platform == "Android") {
alertContent = event.alert;
} else {
alertContent = event.aps.alert;
2016-01-21 15:15:48 +08:00
}
2017-09-22 16:06:44 +08:00
alert("open Notification:" + alertContent);
} catch (exception) {
console.log("JPushPlugin:onOpenNotification" + exception);
}
2016-01-21 15:15:48 +08:00
};
2017-09-22 16:06:44 +08:00
2016-04-08 18:01:27 +08:00
var onReceiveNotification = function(event) {
2017-09-22 16:06:44 +08:00
try {
var alertContent;
if (device.platform == "Android") {
alertContent = event.alert;
} else {
alertContent = event.aps.alert;
2015-03-10 16:37:08 +08:00
}
2017-09-22 16:06:44 +08:00
$("#notificationResult").html(alertContent);
} catch (exception) {
console.log(exception)
}
2016-01-21 15:15:48 +08:00
};
2017-09-22 16:06:44 +08:00
2016-04-08 18:01:27 +08:00
var onReceiveMessage = function(event) {
2017-09-22 16:06:44 +08:00
try {
var message;
if (device.platform == "Android") {
message = event.message;
} else {
message = event.content;
2016-01-21 15:15:48 +08:00
}
2017-09-22 16:06:44 +08:00
$("#messageResult").html(message);
} catch (exception) {
console.log("JPushPlugin:onReceiveMessage-->" + exception);
}
2016-01-21 15:15:48 +08:00
};
2017-09-22 16:06:44 +08:00
2016-04-08 18:01:27 +08:00
var initiateUI = function() {
2017-09-22 16:06:44 +08:00
try {
window.JPush.init();
window.setTimeout(getRegistrationID, 1000);
if (device.platform != "Android") {
window.JPush.setDebugModeFromIos();
window.JPush.setApplicationIconBadgeNumber(0);
} else {
window.JPush.setDebugMode(true);
window.JPush.setStatisticsOpen(true);
}
} catch (exception) {
console.log(exception);
}
$("#setTags").click(function(ev) {
2016-01-21 15:15:48 +08:00
try {
2017-09-22 16:06:44 +08:00
var tag1 = $("#tagText1").val()
var tag2 = $("#tagText2").val()
var tag3 = $("#tagText3").val()
var tags = []
if (tag1) {
tags.push(tag1)
}
if (tag2) {
tags.push(tag2)
}
if (tag3) {
tags.push(tag3)
}
window.JPush.setTags({ sequence: 1, tags: tags },
(result) => {
$("#tagsResult").html(result.tags)
}, (error) => {
2017-09-22 20:13:15 +08:00
alert(error.code)
2017-09-22 16:06:44 +08:00
})
2016-04-08 18:01:27 +08:00
} catch (exception) {
2017-09-22 16:06:44 +08:00
console.log(exception)
2016-01-21 15:15:48 +08:00
}
2017-09-22 16:06:44 +08:00
})
2017-09-22 16:06:44 +08:00
$("#getAllTags").click(function (event) {
window.JPush.getAllTags({ sequence: 2 },
(result) => {
$("#tagsResult").html(result.tags)
}, (error) => {
2017-09-22 20:13:15 +08:00
alert(error.code)
2017-09-22 16:06:44 +08:00
})
})
2016-04-08 18:01:27 +08:00
2017-09-22 16:06:44 +08:00
$("#cleanTags").click(function (event) {
window.JPush.cleanTags({ sequence: 2 },
(result) => {
alert(result.sequence)
$("#tagsResult").html("")
}, (error) => {
2017-09-22 20:13:15 +08:00
alert(error.code)
2017-09-22 16:06:44 +08:00
})
})
$("#setAlias").click(function (event) {
var alias = $("#aliasText").val()
window.JPush.setAlias({ sequence: 1, alias: alias },
(result) => {
$("#aliasResult").html(result.alias)
}, (error) => {
2017-09-22 20:13:15 +08:00
alert(error.code)
2017-09-22 16:06:44 +08:00
})
})
$("#getAlias").click(function (event) {
window.JPush.getAlias({ sequence: 2 },
(result) => {
alert(JSON.stringify(result));
}, (error) => {
2017-09-22 20:13:15 +08:00
alert(error.code)
2017-09-22 16:06:44 +08:00
})
});
$("#deleteAlias").click(function (event) {
window.JPush.deleteAlias({ sequence: 3 },
(result) => {
alert(JSON.stringify(result));
}, (error) => {
2017-09-22 20:13:15 +08:00
alert(error.code)
2017-09-22 16:06:44 +08:00
})
});
};
2016-01-21 15:15:48 +08:00
document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("jpush.openNotification", onOpenNotification, false);
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
2017-09-22 16:06:44 +08:00
</script>
</head>
<body>
2016-04-08 18:01:27 +08:00
<div data-role="page" id="page">
2017-09-22 16:06:44 +08:00
<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>
2016-04-08 18:01:27 +08:00
2017-09-22 16:06:44 +08:00
<div data-role="fieldcontain">
<input type="button" id="setTags" value="Set tags" />
<input type="button" id="getAllTags" value="Get all tags" />
<input type="button" id="cleanTags" value="Clean tags" />
</div>
<div data-role="fieldcontain">
<input type="button" id="setAlias" value="Set alias" />
<input type="button" id="getAlias" value="Get alias" />
<input type="button" id="deleteAlias" value="Delete alias" />
</div>
<div data-role="fieldcontain">
<label id="tagsPrompt">设置 Tag 的结果:</label>
<label id="tagsResult">null</label>
</div>
<div data-role="fieldcontain">
<label id="aliasPrompt">设置 Alias 的结果:</label>
<label id="aliasResult">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>
</div>
</form>
</div>
</div>
</body>
</html>