123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <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">
- var onDeviceReady = function() {
- console.log("JPushPlugin:Device ready!");
- initiateUI();
- };
- var getRegistrationID = function() {
- window.plugins.jPushPlugin.getRegistrationID(onGetRegistrationID);
- };
- var onGetRegistrationID = function(data) {
- try {
- console.log("JPushPlugin:registrationID is " + data);
- if (data.length == 0) {
- var t1 = window.setTimeout(getRegistrationID, 1000);
- }
- $("#registrationId").html(data);
- } catch (exception) {
- console.log(exception);
- }
- };
- var onTagsWithAlias = function(event) {
- 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)
- }
- };
- var onOpenNotification = function(event) {
- try {
- var alertContent;
- if (device.platform == "Android") {
- alertContent = event.alert;
- } else {
- alertContent = event.aps.alert;
- }
- alert("open Notification:" + alertContent);
- } catch (exception) {
- console.log("JPushPlugin:onOpenNotification" + exception);
- }
- };
- var onReceiveNotification = function(event) {
- try {
- var alertContent;
- if (device.platform == "Android") {
- alertContent = event.alert;
- } else {
- alertContent = event.aps.alert;
- }
- $("#notificationResult").html(alertContent);
- } catch (exception) {
- console.log(exception)
- }
- };
- var onReceiveMessage = function(event) {
- try {
- var message;
- if (device.platform == "Android") {
- message = event.message;
- } else {
- message = event.content;
- }
- $("#messageResult").html(message);
- } catch (exception) {
- console.log("JPushPlugin:onReceiveMessage-->" + exception);
- }
- };
- var initiateUI = function() {
- try {
- window.plugins.jPushPlugin.init();
- window.setTimeout(getRegistrationID, 1000);
- if (device.platform != "Android") {
- window.plugins.jPushPlugin.setDebugModeFromIos();
- window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
- } else {
- window.plugins.jPushPlugin.setDebugMode(true);
- window.plugins.jPushPlugin.setStatisticsOpen(true);
- }
- } catch (exception) {
- console.log(exception);
- }
- $("#setTagWithAliasButton").click(function(ev) {
- try {
- var tag1 = $("#tagText1").attr("value");
- var tag2 = $("#tagText2").attr("value");
- var tag3 = $("#tagText3").attr("value");
- var alias = $("#aliasText").attr("value");
- var tags = [];
- if (tag1 != "") {
- tags.push(tag1);
- }
- if (tag2 != "") {
- tags.push(tag2);
- }
- if (tag3 != "") {
- tags.push(tag3);
- }
- window.plugins.jPushPlugin.setTagsWithAlias(tags, alias, function () {
- // Success callback
- console.log(tags + ' - ' + alias)
- });
- } catch (exception) {
- console.log(exception);
- }
- })
- };
- 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>
- <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>
- </div>
- </form>
- </div>
- </div>
- </body>
- </html>
|