- A+
所属分类:uniapp
一,在manifest.json勾选一下Push推送哦
image.png
二,点击配置
image.png
三,配置完成后会自动生成AppID等信息,把这些信息发给后端
image.png
在App.vue里面
onLaunch: function() { initTabBar(); //#ifdef APP-PLUS //开启推送 uni.subscribePush({ provider: "unipush", success: function(res) { console.log("success:" + JSON.stringify(res)); } }); let osname = plus.os.name console.log(osname) if (osname == 'Android') { uni.onPush({ provider: "unipush", success: function() { console.log("监听透传成功"); }, callback: function(data) { console.log("接收到透传数据:" + JSON.stringify(data)); plus.push.createMessage(data.data, {}); } }); } // 监听在线消息事件 if (osname == 'iOS') { plus.push.addEventListener('receive', function(msg) { plus.push.createMessage(msg.content, "LocalMSG", { cover: false }); setTimeout(() => { plus.push.clear(); }, 3000) }, false); } plus.push.addEventListener( "click", //这里写业务逻辑 function(data) { console.log(data); }, false ); plus.push.addEventListener('receive',function(res){ let options = {cover:false}; console.log(res) console.log(res.content) plus.push.createMessage(res.content,res.payload,options); },false) }
作者:yun_71db
链接:https://www.jianshu.com/p/b879e151e125
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。