|
【前段时间因为这个问题,纠结了很长时间,在论坛发帖,找资料,都没能解决】
最后官方看我提问这个问题比较多,由专人与我联系,进行解决,最终成功解决问题,下面将经验分享给大家!
以onOpenNotification为例:
==========================================================
- <script type="text/javascript" src="/cordova.js"></script>
- <script type="text/javascript">
- $(function(){
- JPushInstance();
- });
- var registrationID="";
- var JPushInstance = function() {
- document.addEventListener("deviceready", JPushInstance.prototype.onDeviceReady, false);
- document.addEventListener("jpush.openNotification", JPushInstance.prototype.onOpenNotification, false);
- };
-
- //设备准备好的时候获取注册id
- JPushInstance.prototype.onDeviceReady = function() {
- var self = this;
- window.plugins.jPushPlugin.init();
- //alert("准备获取")
- window.plugins.jPushPlugin.getRegistrationID(function(registrationID) {
- self.registrationID = registrationID;
- alert("registrationID:"+registrationID);//获取初始化ID,此处获取到,才能正常运行
- });
- if (device.platform == "Android") {
- window.plugins.jPushPlugin.setDebugMode(false);
- window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
- } else {
- window.plugins.jPushPlugin.setDebugMode(false);
- window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
- }
- };
- //打开通知的处理
- JPushInstance.prototype.onOpenNotification = function(event) {
- var alertContent;
- var extras;
- var title;
- var content;
- if (device.platform == "Android") {
- alertContent = window.plugins.jPushPlugin.openNotification.alert;
- extras = window.plugins.jPushPlugin.openNotification.extras;
- title = window.plugins.jPushPlugin.openNotification.title;
- content = window.plugins.jPushPlugin.openNotification.content;
- } else {
- alertContent = event.aps.alert;
- extras = event.aps.extras;
- }
- window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
-
- var vv="";
- var kk="";
- $.each(extras,function(k,v){
- vv+=v+",";
- kk+=k+",";
- })
- var array = vv.split(",");
-
- alert(title);//获取推送标题
- alert(array[1]);//获取附加字段的值
- alert(alertContent)//获取提送内容
- };
- </script>
复制代码
|
评分
-
查看全部评分
|