苍山暮色烟雨迟
苍山暮色烟雨迟
  • 发布:2023-09-12 10:10
  • 更新:2023-09-12 10:10
  • 阅读:107

【报Bug】unipush部分机型离线通知唤起app后接收不到参数。

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: maxOS Sonoma 14.0

HBuilderX类型: 正式

HBuilderX版本号: 3.8.12

手机系统: Android

手机系统版本号: Android 11

手机厂商: 1+

手机机型: 7T

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

App.vue

// #ifdef APP-PLUS  
    import {initPushInfo} from '@/plugins/pushANDNoticfication.js'  
    // #endif  

onLaunch: function() {  
            const _this = this;  
            onPageChange()  
            // #ifdef APP-PLUS  
            plus.screen.lockOrientation('portrait-primary'); //锁定  
            try {  
                initPushInfo()  
            } catch(e) {  
                console.log(e);  
            }  
// #endif  
}

pushANDNoticfication.js

import * as Api from "../api/index.js"  

export const initPushInfo = () => {  
    // console.log('initPushInfo');  
    // 获取本机的客户端ID  
    uni.getPushClientId({  
        success(res) {  
            // console.log('获取cid', res);  
            uni.$store.dispatch('userModule/SAVE_PUSH_CID', {  
                cid: res.cid  
            })  
        }  
    })  

    // uni.onPushMessage(res => {  
    //  console.log('收到推送信息:', res);  
    //  const {  
    //      push_type,  
    //      msg_type,  
    //      msg_id,  
    //      push_id  
    //  } = res.data.payload;  
    //  let url = '/pages'  
    //  if (push_type === 'content') {  
    //      switch (msg_type) {  
    //          case 'graphic':  
    //              url += '/index/newsDetail?id=' + msg_id;  
    //              break;  
    //          case 'topic':  
    //              url += '/index/topic?id=' + msg_id;  
    //              break;  
    //          case 'subject':  
    //              url += '/index/special?id=' + msg_id;  
    //              break;  
    //          case 'video':  
    //              url += '/video/video?state=video&id=' + msg_id;  
    //              break;  
    //          case 'minivideo':  
    //              url += '/video/immersive?content_type=2&id=' + msg_id;  
    //              break;  
    //          case 'live':  
    //              url += '/video/live?id=' + msg_id;  
    //              break;  
    //          case 'album':  
    //              url += '/video/album?id=' + msg_id;  
    //              break;  
    //          case 'vote':  
    //              url += '/content/vote?id=' + msg_id;  
    //              break;  
    //          case 'gallery':  
    //              url += '/content/gallery?id=' + msg_id;  
    //              break;  
    //          default:  
    //              break;  
    //      }  
    //  }  
    //  if (url === '/pages') return  
    //  // 为了解决返回会到splash页面的问题  
    //  const pages = getCurrentPages()  
    //  console.log('pages-length:', pages.length);  
    //  console.log('pages-last-route:', pages[pages.length - 1].route);  
    //  if (pages.length === 0 || pages[pages.length - 1].route === 'pages/common/splash') {  
    //      console.log('先跳转到首页,gogogo');  
    //      uni.$utils.navTo('/pages/index/index')  
    //  }  
    //  console.log('当前页面路径:', pages[pages.length - 1]['$page']['fullPath']);  
    //  console.log('要跳转到的url:', url);  
    //  if(pages[pages.length - 1]['$page']['fullPath'] === url) {  
    //      console.log('当前页面就是推送页面,不做处理');  
    //      return  
    //  }  
    //  console.log('通过验证,开始跳转');  
    //  setTimeout(() => {  
    //      console.log('跳转到指定页面');  
    //      uni.$utils.navTo(url)  
    //      Api.report_push_act({  
    //          push_cid: uni.$store.state.userModule.pushCID || '',  
    //          push_id  
    //      })  
    //  }, 500)  
    // })  

    plus.push.addEventListener('receive', function(msg) {  
        console.log('receive',msg);  
    }, false)  

    plus.push.addEventListener('click', function(res) {  
        console.log('click',res);  
        const {  
            push_type,  
            msg_type,  
            msg_id,  
            push_id  
        } = res.payload;  
        let url = '/pages'  
        if (push_type === 'content') {  
            switch (msg_type) {  
                case 'graphic':  
                    url += '/index/newsDetail?id=' + msg_id;  
                    break;  
                case 'topic':  
                    url += '/index/topic?id=' + msg_id;  
                    break;  
                case 'subject':  
                    url += '/index/special?id=' + msg_id;  
                    break;  
                case 'video':  
                    url += '/video/video?state=video&id=' + msg_id;  
                    break;  
                case 'minivideo':  
                    url += '/video/immersive?content_type=2&id=' + msg_id;  
                    break;  
                case 'live':  
                    url += '/video/live?id=' + msg_id;  
                    break;  
                case 'album':  
                    url += '/video/album?id=' + msg_id;  
                    break;  
                case 'vote':  
                    url += '/content/vote?id=' + msg_id;  
                    break;  
                case 'gallery':  
                    url += '/content/gallery?id=' + msg_id;  
                    break;  
                default:  
                    break;  
            }  
        }  
        if (url === '/pages') return  
        // 为了解决返回会到splash页面的问题  
        const pages = getCurrentPages()  
        console.log('pages-length:', pages.length);  
        console.log('pages-last-route:', pages[pages.length - 1].route);  
        if (pages.length === 0 || pages[pages.length - 1].route === 'pages/common/splash') {  
            console.log('先跳转到首页,gogogo');  
            uni.$utils.navTo('/pages/index/index')  
        }  
        console.log('当前页面路径:', pages[pages.length - 1]['$page']['fullPath']);  
        console.log('要跳转到的url:', url);  
        if(pages[pages.length - 1]['$page']['fullPath'] === url) {  
            console.log('当前页面就是推送页面,不做处理');  
            return  
        }  
        console.log('通过验证,开始跳转');  
        setTimeout(() => {  
            console.log('跳转到指定页面');  
            uni.$utils.navTo(url)  
            Api.report_push_act({  
                push_cid: uni.$store.state.userModule.pushCID || '',  
                push_id  
            })  
        }, 500)  
    }, false)  
}  

操作步骤:

引用以上代码,通过云函数推送。

预期结果:

离线推送后,点击通知消息,唤起app后进行相关逻辑处理

实际结果:

唤起app后收不到通知消息

bug描述:

项目集成unipush2.0已经配置离线推送相关channel,推送能够正常收到。
项目在前台或者后台时,收到推送可以正常打开app,可以出发uni.onPushMessage 并进行相关逻辑处理。
但是在app被杀死的情况下,通过离线推送的消息,点击只会唤起app,无法触发uni.onPushMessage
以及使用

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

来监听,都无法触发。
目前除了1+7T(氢os) 还有客户反馈的部分其他机型 华为nova6 vivoX80也有此问题

2023-09-12 10:10 负责人:无 分享
已邀请:

要回复问题请先登录注册