index.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>JPush Phonegap Simple Demo</title>
  6. <link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css" />
  7. <script type="text/javascript" src="js/jquery.js"></script>
  8. <script type="text/javascript" src="js/jquery.mobile-1.1.1.js"></script>
  9. <script type="text/javascript" src="cordova.js"></script>
  10. <script type="text/javascript">
  11. var onDeviceReady = function() {
  12. console.log("JPushPlugin:Device ready!");
  13. initiateUI();
  14. };
  15. var getRegistrationID = function() {
  16. window.plugins.jPushPlugin.getRegistrationID(onGetRegistrationID);
  17. };
  18. var onGetRegistrationID = function(data) {
  19. try {
  20. console.log("JPushPlugin:registrationID is " + data);
  21. if (data.length == 0) {
  22. var t1 = window.setTimeout(getRegistrationID, 1000);
  23. }
  24. $("#registrationId").html(data);
  25. } catch (exception) {
  26. console.log(exception);
  27. }
  28. };
  29. var onTagsWithAlias = function(event) {
  30. try {
  31. console.log("onTagsWithAlias");
  32. var result = "result code:" + event.resultCode + " ";
  33. result += "tags:" + event.tags + " ";
  34. result += "alias:" + event.alias + " ";
  35. $("#tagAliasResult").html(result);
  36. } catch (exception) {
  37. console.log(exception)
  38. }
  39. };
  40. var onOpenNotification = function(event) {
  41. try {
  42. var alertContent;
  43. if (device.platform == "Android") {
  44. alertContent = event.alert;
  45. } else {
  46. alertContent = event.aps.alert;
  47. }
  48. alert("open Notification:" + alertContent);
  49. } catch (exception) {
  50. console.log("JPushPlugin:onOpenNotification" + exception);
  51. }
  52. };
  53. var onReceiveNotification = function(event) {
  54. try {
  55. var alertContent;
  56. if (device.platform == "Android") {
  57. alertContent = event.alert;
  58. } else {
  59. alertContent = event.aps.alert;
  60. }
  61. $("#notificationResult").html(alertContent);
  62. } catch (exception) {
  63. console.log(exception)
  64. }
  65. };
  66. var onReceiveMessage = function(event) {
  67. try {
  68. var message;
  69. if (device.platform == "Android") {
  70. message = event.message;
  71. } else {
  72. message = event.content;
  73. }
  74. $("#messageResult").html(message);
  75. } catch (exception) {
  76. console.log("JPushPlugin:onReceiveMessage-->" + exception);
  77. }
  78. };
  79. var initiateUI = function() {
  80. try {
  81. window.plugins.jPushPlugin.init();
  82. window.setTimeout(getRegistrationID, 1000);
  83. if (device.platform != "Android") {
  84. window.plugins.jPushPlugin.setDebugModeFromIos();
  85. window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
  86. } else {
  87. window.plugins.jPushPlugin.setDebugMode(true);
  88. window.plugins.jPushPlugin.setStatisticsOpen(true);
  89. }
  90. } catch (exception) {
  91. console.log(exception);
  92. }
  93. $("#setTagWithAliasButton").click(function(ev) {
  94. try {
  95. var tag1 = $("#tagText1").attr("value");
  96. var tag2 = $("#tagText2").attr("value");
  97. var tag3 = $("#tagText3").attr("value");
  98. var alias = $("#aliasText").attr("value");
  99. var tags = [];
  100. if (tag1 != "") {
  101. tags.push(tag1);
  102. }
  103. if (tag2 != "") {
  104. tags.push(tag2);
  105. }
  106. if (tag3 != "") {
  107. tags.push(tag3);
  108. }
  109. window.plugins.jPushPlugin.setTagsWithAlias(tags, alias, function () {
  110. // Success callback
  111. console.log(tags + ' - ' + alias)
  112. });
  113. } catch (exception) {
  114. console.log(exception);
  115. }
  116. })
  117. };
  118. document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
  119. document.addEventListener("deviceready", onDeviceReady, false);
  120. document.addEventListener("jpush.openNotification", onOpenNotification, false);
  121. document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
  122. document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
  123. </script>
  124. </head>
  125. <body>
  126. <div data-role="page" id="page">
  127. <div data-role="content">
  128. <form>
  129. <div class="ui-body ui-body-b">
  130. <div data-role="fieldcontain">
  131. <center>
  132. <h3>JPushPlugin Example</h3>
  133. </center>
  134. <span name="alias" id="alias"></span>
  135. <hr/>
  136. <label>RegistrationID: </label>
  137. <label id="registrationId">null</label>
  138. </div>
  139. <div data-role="fieldcontain">
  140. <label>Tags: </label>
  141. <table>
  142. <tr>
  143. <td>
  144. <input type="text" id="tagText1" />
  145. </td>
  146. </tr>
  147. <tr>
  148. <td>
  149. <input type="text" id="tagText2" />
  150. </td>
  151. </tr>
  152. <tr>
  153. <td>
  154. <input type="text" id="tagText3" />
  155. </td>
  156. </tr>
  157. </table>
  158. <label>Alias: </label>
  159. <table>
  160. <tr>
  161. <td>
  162. <input type="text" id="aliasText" />
  163. </td>
  164. </tr>
  165. </table>
  166. </div>
  167. <div data-role="fieldcontain">
  168. <input type="button" id="setTagWithAliasButton"
  169. value="Add tag and alias" />
  170. </div>
  171. <div data-role="fieldcontain">
  172. <label id="tagAliasPrompt">设置tag/alias结果:</label>
  173. <label id="tagAliasResult">null</label>
  174. </div>
  175. <div data-role="fieldcontain">
  176. <label id="notificationPrompt">接受的通知内容:</label>
  177. <label id="notificationResult">null</label>
  178. </div>
  179. <div data-role="fieldcontain">
  180. <label id="messagePrompt">接受的自定义消息:</label>
  181. <label id="messageResult">null</label>
  182. </div>
  183. </div>
  184. </form>
  185. </div>
  186. </div>
  187. </body>
  188. </html>