[Uniapp] Solve the error plus not defined when pushing

The code in the official document is a bit problematic. You can call the plus code with the following delay and wait for plus to load.

In addition, add the conditional compilation, only the code below the app will compile

                // #ifdef APP-PLUS
                     // trigger when the page loads   
                    setTimeout(function(){
                         if (plus){
                             var pinf = plus.push.getClientInfo();
                             var cid = pinf.clientid; // Client ID 
                            console.log (cid);
                              // Monitor system notification bar message click event 
                             plus.push.addEventListener( ' click ' , function(msg){  
                                  // Business logic code for processing click messages   
                             }, false);  
                              // Monitor and receive transparent message events   
                             plus.push.addEventListener( ' receive ' , function(msg){  
                                  // Business logic code for processing transparent messages   
                                 var options = {cover: false };
                                 plus.push.createMessage(msg, " RemoteMSG " ,options);
                             }, false );
                        }
                    }, 4000 );
                 // #endif

client_id can be obtained

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *