jeawy
jeawy
  • 发布:2020-03-07 13:10
  • 更新:2020-09-02 16:05
  • 阅读:2562

为什么透传消息会自动将app(安卓)从后台切换至前台?

分类:uni-app

我们在做app的持续定位。
在安卓版本中,根据官方文档https://uniapp.dcloud.io/api/location/location 采用透传消息定时激活app,来保证安卓版本的app一致在线采集位置信息。

目前碰到的问题:1 三星手机(s9 )上虽然用了透传消息,但是app切换到后台之后,即使服务器端推送透传消息,app端也似乎被杀了。
2 三星手机、华为手机都会有app收到透传消息后,会自动从后台切换至前台的问题,具体描述:打开app,开启定位(使用plus.geolocation.watchPosition持续定位),切换到后台,服务器端定时(2分钟一次)发送透传消息,当app端收到透传消息之后,app会自动从后台切换至前台。

透传消息的原理不是客户端只收消息不自己做处理吗?按道理来说也不会自动将app切换至前台啊。

下面是我的app端代码和服务器端代码:
app端:
在app.vue中

onLaunch: function() {   
            // #ifdef APP-PLUS  
            plus.screen.lockOrientation('portrait-primary');  
            plus.push.addEventListener("receive", function(msg) {    
            //获取透传数据     

                               //将透传消息记录到日志中  
                var time = new Date();   
                var time1 = time.getFullYear()   '-'   (time.getMonth()   1)   '-'   
                          time.getDate()   ' '   time.getHours()    
                    ':'   time.getMinutes()   ':'   time.getSeconds();  
                var lo = "<h4>_handleReceivePush: " time1  "</h4>"   JSON.stringify(msg) ;  

                uni.setStorageSync('log', lo   uni.getStorageSync('log')   "<br/>")   
                                // 日志记录结束  

            }, false);    
            // #endif  
        }

服务端:(服务端是参考个推的服务端代码示例写的)
python语言:

def sendTransmissionList(cids, transmissionContent, payload):  
    """  
    透传消息模板:多个cids发送透传消息  
    """  
    push = IGeTui(HOST, APPKEY, MASTERSECRET)  
    template = TransmissionTemplate()  
    template.transmissionType = 1  
    template.appId = APPID  
    template.appKey = APPKEY  
    template.transmissionContent = transmissionContent  

    notify = Notify()  
    notify.title = "titleee"  
    notify.content = "contentee"  
    notify.payload = 'payloadtest'  
    notify.type = NotifyInfo._payload  

    notify.title = "titleee"  
    notify.content = "contentee"  
    notify.intent = "intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component=com.****.****/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=透传标题;S.content=透传内容;S.payload=透传;end"  
    notify.type = NotifyInfo._intent   
    template.set3rdNotifyInfo(notify)   

    apn = APNPayload()   
    apn.badge = 2  
    apn.sound = ""  
    apn.addCustomMsg("payload", payload)  
    template.setApnInfo(apn)   

    #定义"AppMessage"类型消息对象,设置消息内容模板、发送的目标App列表、是否支持离线发送、以及离线消息有效期(单位毫秒)  
    message = IGtListMessage()  
    message.data = template  
    message.isOffline = True  
    message.offlineExpireTime = 1000 * 600  
    message.pushNetWorkType = 0  
    arr = []  
    for cid in cids:  
        target = Target()  
        target.appId = APPID  
        target.clientId = cid  
        arr.append(target)  
    contentId = push.getContentId(message, 'ToList')  
    ret = push.pushMessageToList(contentId, arr)  

    logger.debug(json.dumps(ret))  
    return ret  
def send(cids):  
      // 发送透传消息,cids是cid的一个列表  
       transmissionContent = "轨迹"   str(uuid.uuid1())   
        payload = {"uuid": str(uuid.uuid1())}  
        sendTransmissionList(cids, transmissionContent,  payload)  
2020-03-07 13:10 负责人:无 分享
已邀请:
jeawy

jeawy (作者)

自问自答~~~

jeawy

jeawy (作者)

有没有人可以帮忙解答下????谢谢

jeawy

jeawy (作者)

自己顶下

jeawy

jeawy (作者)

????

jeawy

jeawy (作者)

????有没有人给指条明路啊?

jeawy

jeawy (作者)

重新起了个项目,测试了下透传消息,发现切换到后台之后,收到透传消息后不会自动切换至前台,那么我的情况收到为什么会自动切换前台呢?
难到是plus.geolocation.watchPosition????

  • jeawy (作者)

    测了下:跟plus.geolocation.watchPosition这个也没有关系,得看看其他问题了。

    2020-03-12 17:24

jeawy

jeawy (作者)

问题解决 了:根本原因是对透传消息不熟。
个推的透传消息有两种类型:
1:立即启动APP(不推荐使用,影响客户体验)
2:客户端收到消息后需要自行处理
通过设置TransmissionTemplate的transmissionType 为2设置app收到透传消息后,不自动启动app。
template = TransmissionTemplate()
"""
搭配transmissionContent使用,可选值为1、2;
1:立即启动APP(不推荐使用,影响客户体验)
2:客户端收到消息后需要自行处理
"""
template.transmissionType = 2

8***@qq.com

8***@qq.com

但是穿透消息设置transmissionType 为2时,app在后台时,收不到穿透消息啊

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