l***@sina.com
l***@sina.com
  • 发布:2018-03-23 09:41
  • 更新:2020-05-15 17:36
  • 阅读:7287

ios app 在前台时,个推推送的消息,receive 收到消息后创建本地消息(plus.push.createmessage()),无限执行,是怎么回事?怎么判断呢?

分类:HTML5+

ios app 在前台时,receive 收到消息创建本地消息,无限执行,怎么判断,消息为标准的透传消息;

plus.push.addEventListener('receive',function(msg){
if(plus.os.name.toUpperCase()=="IOS")
{

console.log((typeof(msg)=="object"));
console.log(msg.payload);

if(msg.payload.indexOf("nolocalMsg")>-1)
{
var gtpush = msg.payload;
gtpush = gtpush.substr(10);
plus.push.createMessage(msg.content,gtpush,{title:msg.title})
}

}
else
{

}
},false);

一条推送消息:打印出的log 是这样的

[LOG] : true
[LOG] : nolocalMsgBDA9F1E19A334BAC900E5A3F9CF86260
[LOG] : true
[LOG] : nolocalMsgBDA9F1E19A334BAC900E5A3F9CF86260
[LOG] : true
[LOG] : nolocalMsgBDA9F1E19A334BAC900E5A3F9CF86260
[LOG] : true
[LOG] : nolocalMsgBDA9F1E19A334BAC900E5A3F9CF86260
[LOG] : true
[LOG] : nolocalMsgBDA9F1E19A334BAC900E5A3F9CF86260
[LOG] : true
[LOG] : nolocalMsgBDA9F1E19A334BAC900E5A3F9CF86260
[LOG] : true
[LOG] : BDA9F1E19A334BAC900E5A3F9CF86260
[LOG] : true
[LOG] : BDA9F1E19A334BAC900E5A3F9CF86260
[LOG] : true
[LOG] : BDA9F1E19A334BAC900E5A3F9CF86260
[LOG] : true
[LOG] : BDA9F1E19A334BAC900E5A3F9CF86260
[LOG] : true
[LOG] : BDA9F1E19A334BAC900E5A3F9CF86260
[LOG] : true
[LOG] : BDA9F1E19A334BAC900E5A3F9CF86260

为什么会这样呢?

2018-03-23 09:41 负责人:无 分享
已邀请:
jtshushu

jtshushu - 擅长:PHP-Thinkphp Python MUI UniApp Vuejs Bootstrap Jq Logo设计 广告设计 网页设计 有项目上需要联系我微信号:jtshushu66

uniapp解决

plus.push.addEventListener('receive', function(message) {  

                    plus.nativeUI.toast('push receive');   
                     console.log(message);  

                    if(message.type=='receive'){  
                        //plus.push.createMessage(msg.content,msg.title);  
                            plus.push.createMessage(message.content);  

                     }  

                }); 
jtshushu

jtshushu - 擅长:PHP-Thinkphp Python MUI UniApp Vuejs Bootstrap Jq Logo设计 广告设计 网页设计 有项目上需要联系我微信号:jtshushu66

解决了

plus.push.addEventListener('receive', function(message) {    

                    plus.nativeUI.toast('push receive');     
                     console.log(message);                   
                    if(message.type=='receive'){    
                        //plus.push.createMessage(msg.content,msg.title);    
                            plus.push.createMessage(message.content);    

                     }    

                }); 
回梦無痕

回梦無痕 - 暂停服务

因为你的createmessage写在了receive中,然后createmessage会触发receive。就无限循环了

  • l***@sina.com (作者)

    老师你好!,这是我监听到的消息receive 中通过判断,msg.payload 是否还有特殊字符,是否继续执行

    plus.push.addEventListener('receive',function(msg){

    if(getOsType()=="IOS")

    {


                console.log((typeof(msg)=="object"));  
    console.log(msg.payload);

    if(msg.payload.indexOf("nolocalMsg")>-1)
    {
    var gtpush = msg.payload;
    gtpush = gtpush.substr(10);
    plus.push.createMessage(msg.content,gtpush,{title:msg.title})
    }

    }

    else

    {


            }  
    },false);

    一条推送消息:打印出的log 是这样的


    [LOG] : true

    [LOG] : nolocalMsgBDA9F1E19A334BAC900E5A3F9CF86260

    [LOG] : true

    [LOG] : nolocalMsgBDA9F1E19A334BAC900E5A3F9CF86260

    [LOG] : true

    [LOG] : nolocalMsgBDA9F1E19A334BAC900E5A3F9CF86260

    [LOG] : true

    [LOG] : nolocalMsgBDA9F1E19A334BAC900E5A3F9CF86260

    [LOG] : true

    [LOG] : nolocalMsgBDA9F1E19A334BAC900E5A3F9CF86260

    [LOG] : true

    [LOG] : nolocalMsgBDA9F1E19A334BAC900E5A3F9CF86260

    [LOG] : true

    [LOG] : BDA9F1E19A334BAC900E5A3F9CF86260

    [LOG] : true

    [LOG] : BDA9F1E19A334BAC900E5A3F9CF86260

    [LOG] : true

    [LOG] : BDA9F1E19A334BAC900E5A3F9CF86260

    [LOG] : true

    [LOG] : BDA9F1E19A334BAC900E5A3F9CF86260

    [LOG] : true

    [LOG] : BDA9F1E19A334BAC900E5A3F9CF86260

    [LOG] : true

    [LOG] : BDA9F1E19A334BAC900E5A3F9CF86260

    2018-03-23 11:52

王者地带

王者地带 - 5+混合APP开发教程网 | http://www.html5-app.com | 咨询QQ: 2564034335

//苹果只能用透传消息, 有两种应用在前台是走个推或其他推送,当应用在后台时,才是走苹果的APS道通  
plus.push.addEventListener("click", function(msg)   
{  
          //msg 消息中,有个APS的,如果不为NULL ,就是走苹果的APS通道,否则是走个推或其他通道  
             if(msg["aps"]!=null)  
        {  
                         // 苹果的APS通道  
                }  

 }
1***@qq.com

1***@qq.com - web前端

plus.push.createmessage()苹果手机不生效,安卓都可以,可以监听到recive,不知道是什么原因

s***@163.com

s***@163.com

您好,这个一直循环的问题怎么解决的

  • 2***@qq.com

    if(msg.type=='receive'){plus.push.createMessage(msg.content,msg.title);} 我是这样搞的不知道对不对反正不循环了

    2019-12-28 00:07

ancientry

ancientry

您好,循坏问题解决了吗??我也是遇到到这个问题了,急求

  • 2***@qq.com

    if(msg.type=='receive'){plus.push.createMessage(msg.content,msg.title);}

    2019-12-28 00:06

1525941857QQ

1525941857QQ - 忍冬

您好,循坏问题解决了吗??遇到相同问题,急求解决办法!!

  • 2***@qq.com

    if(msg.type=='receive'){plus.push.createMessage(msg.content,msg.title);}

    2019-12-28 00:07

  • 4***@qq.com

    回复 2***@qq.com: 您好,请问您这段代码是写在plus.push.addEventListener('receive', function(msg){这个监听事件里面吗

    2019-12-30 08:43

  • 2***@qq.com

    回复 4***@qq.com: 是的 反正解决了 具体不知道为啥没分析

    2020-01-10 16:47

  • 爱吃鱼的靖哥哥

    回复 2***@qq.com: 我也用的这种方法,本地创建的消息里没有type属性

    2020-03-09 17:14

该问题目前已经被锁定, 无法添加新回复