起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

12
返回列表 发新帖
楼主: outeng

[结贴] 极光推送,app如何获取自定义字段和标题内容!

[复制链接]

9

主题

31

帖子

83

积分

初级会员

Rank: 2

积分
83
QQ
 楼主| 发表于 2016-9-26 15:57:25 | 显示全部楼层
cgrddv 发表于 2016-9-26 14:41
return new JPushInstance();
改一下,直接newJPushInstance();

试过了,还是不行,我在最底层alert下,能执行过去,感觉JPushInstance没执行,请指教!谢谢
  1. <script type="text/javascript" src="/cordova.js"></script>
  2. <script type="text/javascript">
  3. $(function() {

  4.         var JPushInstance = function() {
  5.                 if (window.plugins && window.plugins.jPushPlugin) {
  6.                         document.addEventListener("deviceready", this.onDeviceReady.bind(this), false);
  7.                         document.addEventListener("jpush.openNotification", this.onOpenNotification.bind(this), false);
  8.                         document.addEventListener("jpush.receiveNotification", this.onReceiveNotification.bind(this), false);
  9.                         document.addEventListener("jpush.receiveMessage", this.onReceiveMessage.bind(this), false);
  10.                 }
  11.         };
  12.        
  13.         //hcr 解决第一次获取失败的问题
  14.         JPushInstance.prototype.getRegistrationID = function(){
  15.                  var dtd = $.Deferred();
  16.                  if (this.registrationID){
  17.                          dtd.resolve(this.registrationID);
  18.                  }else{
  19.                          if (window.plugins && window.plugins.jPushPlugin){
  20.                                  window.plugins.jPushPlugin.getRegistrationID(function(registrationID) {
  21.                                          self.registrationID = registrationID;
  22.                                          if (self.registrationID){
  23.                                                  dtd.resolve(self.registrationID);         
  24.                                          }else{
  25.                                                  dtd.reject();
  26.                                          }
  27.                                  });
  28.                          }else{
  29.                                  dtd.reject();
  30.                          }
  31.                  }
  32.                  return dtd.promise();
  33.         };
  34.        

  35.         JPushInstance.prototype.onDeviceReady = function() {
  36.                 var self = this;
  37.                 window.plugins.jPushPlugin.init();
  38.                 window.plugins.jPushPlugin.getRegistrationID(function(registrationID) {
  39.                         self.registrationID = registrationID;
  40.                 });
  41.                 if (device.platform == "Android") {
  42.                         window.plugins.jPushPlugin.setDebugMode(false);
  43.                         window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
  44.                 } else {
  45.                         window.plugins.jPushPlugin.setDebugMode(false);
  46.                         window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
  47.                 }
  48.         };

  49.         JPushInstance.prototype.onOpenNotification = function(event) {
  50.                 var alertContent;
  51.                 if (device.platform == "Android") {
  52.                         alertContent = window.plugins.jPushPlugin.openNotification.alert;
  53.                 } else {
  54.                         alertContent = event.aps.alert;
  55.                 }
  56.                 window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
  57.                 alert(alertContent);
  58.         };

  59.         JPushInstance.prototype.onReceiveNotification = function(event) {
  60.                 var alertContent;
  61.         if(device.platform == "Android"){
  62.                 alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
  63.         }else{
  64.                 alertContent   = event.aps.alert;
  65.         }
  66.         window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
  67.                 alert(alertContent);
  68.         };

  69.         JPushInstance.prototype.onReceiveMessage = function() {
  70.                 var message;
  71.         if(device.platform == "Android"){
  72.                         message = window.plugins.jPushPlugin.receiveMessage.message;
  73.         }else{
  74.               message   = event.content;
  75.         }
  76.         window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
  77.                 alert(message);
  78.         };

  79.         new JPushInstance();
  80.         alert(123)
  81. });

  82. </script>
复制代码
回复 支持 反对

使用道具 举报

9

主题

31

帖子

83

积分

初级会员

Rank: 2

积分
83
QQ
 楼主| 发表于 2016-9-26 17:09:32 | 显示全部楼层
cgrddv 发表于 2016-9-26 14:41
return new JPushInstance();
改一下,直接newJPushInstance();

现在是这样操作的,没有效果呢?
回复 支持 反对

使用道具 举报

9

主题

31

帖子

83

积分

初级会员

Rank: 2

积分
83
QQ
 楼主| 发表于 2016-9-26 17:10:20 | 显示全部楼层
cgrddv 发表于 2016-9-26 14:41
return new JPushInstance();
改一下,直接newJPushInstance();

我现在这个写法没有问题吧?
===========================================
  1. <script type="text/javascript" src="/cordova.js"></script>
  2. <script type="text/javascript">
  3. $(function() {

  4.         var JPushInstance = function() {
  5.                 if (window.plugins && window.plugins.jPushPlugin) {
  6.                         document.addEventListener("deviceready", this.onDeviceReady.bind(this), false);
  7.                         document.addEventListener("jpush.openNotification", this.onOpenNotification.bind(this), false);
  8.                         document.addEventListener("jpush.receiveNotification", this.onReceiveNotification.bind(this), false);
  9.                         document.addEventListener("jpush.receiveMessage", this.onReceiveMessage.bind(this), false);
  10.                 }
  11.         };
  12.        
  13.         //hcr 解决第一次获取失败的问题
  14.         JPushInstance.prototype.getRegistrationID = function(){
  15.                  var dtd = $.Deferred();
  16.                  if (this.registrationID){
  17.                          dtd.resolve(this.registrationID);
  18.                  }else{
  19.                          if (window.plugins && window.plugins.jPushPlugin){
  20.                                  window.plugins.jPushPlugin.getRegistrationID(function(registrationID) {
  21.                                          self.registrationID = registrationID;
  22.                                          if (self.registrationID){
  23.                                                  dtd.resolve(self.registrationID);         
  24.                                          }else{
  25.                                                  dtd.reject();
  26.                                          }
  27.                                  });
  28.                          }else{
  29.                                  dtd.reject();
  30.                          }
  31.                  }
  32.                  return dtd.promise();
  33.         };
  34.        

  35.         JPushInstance.prototype.onDeviceReady = function() {
  36.                 var self = this;
  37.                 window.plugins.jPushPlugin.init();
  38.                 window.plugins.jPushPlugin.getRegistrationID(function(registrationID) {
  39.                         self.registrationID = registrationID;
  40.                 });
  41.                 if (device.platform == "Android") {
  42.                         window.plugins.jPushPlugin.setDebugMode(false);
  43.                         window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
  44.                 } else {
  45.                         window.plugins.jPushPlugin.setDebugMode(false);
  46.                         window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
  47.                 }
  48.         };

  49.         JPushInstance.prototype.onOpenNotification = function(event) {
  50.                 var alertContent;
  51.                 if (device.platform == "Android") {
  52.                         alertContent = window.plugins.jPushPlugin.openNotification.alert;
  53.                 } else {
  54.                         alertContent = event.aps.alert;
  55.                 }
  56.                 window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
  57.                 alert(alertContent);
  58.         };

  59.         JPushInstance.prototype.onReceiveNotification = function(event) {
  60.                 var alertContent;
  61.         if(device.platform == "Android"){
  62.                 alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
  63.         }else{
  64.                 alertContent   = event.aps.alert;
  65.         }
  66.         window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
  67.                 alert(alertContent);
  68.         };

  69.         JPushInstance.prototype.onReceiveMessage = function() {
  70.                 var message;
  71.         if(device.platform == "Android"){
  72.                         message = window.plugins.jPushPlugin.receiveMessage.message;
  73.         }else{
  74.               message   = event.content;
  75.         }
  76.         window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
  77.                 alert(message);
  78.         };

  79.         new JPushInstance();

  80. });

  81. </script>
复制代码
回复 支持 反对

使用道具 举报

91

主题

13万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
35924
发表于 2016-9-26 17:54:44 | 显示全部楼层
就极光推送插件不执行吗?调用其他的插件看看是否执行
远程的联系方法QQ1392416607,添加好友时,需在备注里注明其论坛名字及ID,公司等信息
发远程时同时也发一下帖子地址,方便了解要解决的问题  WeX5教程  WeX5下载



如按照该方法解决,请及时跟帖,便于版主结贴
回复 支持 反对

使用道具 举报

9

主题

31

帖子

83

积分

初级会员

Rank: 2

积分
83
QQ
 楼主| 发表于 2016-9-27 09:54:45 | 显示全部楼层
jishuang 发表于 2016-9-26 17:54
就极光推送插件不执行吗?调用其他的插件看看是否执行

其他插件执行,极光推送不执行!,13#是我的极光推送写法!请指教,谢谢啦!
回复 支持 反对

使用道具 举报

9

主题

31

帖子

83

积分

初级会员

Rank: 2

积分
83
QQ
 楼主| 发表于 2016-10-11 11:05:32 | 显示全部楼层

可以结贴了,一解决!

http://bbs.wex5.com/thread-105858-1-1.html
回复 支持 反对

使用道具 举报

75

主题

486

帖子

862

积分

高级会员

Rank: 4

积分
862
QQ
发表于 2016-10-11 11:13:42 | 显示全部楼层
顶一下`
http://bbs.justep.com/thread-49855-1-1.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-5-8 10:53 , Processed in 0.062530 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表