[uniapp] 解決推送時報錯plus not defined


官方文檔里的代碼有點點問題 , 可以按照下面這樣延時去調用plus的代碼 , 等待plus加載完畢

另外增加上條件編譯 , 只有在app下面這段代碼才會編譯

                //#ifdef APP-PLUS
                    // 頁面加載時觸發  
                    setTimeout(function(){
                        if(plus){
                            var pinf = plus.push.getClientInfo();
                            var cid = pinf.clientid;//客戶端標識 
                            console.log(cid);
                             //監聽系統通知欄消息點擊事件
                             plus.push.addEventListener('click', function(msg){  
                                 //處理點擊消息的業務邏輯代碼  
                             }, false);  
                             //監聽接收透傳消息事件  
                             plus.push.addEventListener('receive', function(msg){  
                                 //處理透傳消息的業務邏輯代碼  
                                 var options = {cover:false};
                                 plus.push.createMessage(msg,"RemoteMSG",options);
                             }, false);
                        }
                    },4000);
                //#endif

client_id能獲取到

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM