其他分享
首页 > 其他分享> > uniapp推送unipush使用

uniapp推送unipush使用

作者:互联网

1.manifest.json  ---模块化中开启unipush

2.uniapp开发后台配置项目包名签名等---具体获取---打包信息---微信开放平台

ps:签名为特殊格式,需在java环境下查看证书密钥文件获取----

3.app.vue文件中配置监听信息:

例子:

// 监听信息
var info = plus.push.getClientInfo()
// 使用5+App的方式进行监听消息推送
plus.push.addEventListener("click", function(msg) {
console.log("click:" + JSON.stringify(msg));
console.log(msg.payload);
console.log(JSON.stringify(msg));
// onLaunch 生命周期里,页面跳转有问题,跳不过去
// 应该是页面还没加载,加上定时后,就可以了;
setTimeout(() => {
uni.navigateTo({
url: 'pages/index/index'
})
}, 1000)
}, false);
// 监听在线消息事件
plus.push.addEventListener("receive", function(msg) {
//业务代码
console.log("recevice:" + JSON.stringify(msg))
}, false);

 

4.获取设备clientId发送后端

uni.getProvider({
service: 'push',
success: e => {
that.provider = e.provider;
uni.subscribePush({
provider: that.provider[0],
success: function(res) {
var inf = plus.push.getClientInfo();

if (uni.getSystemInfoSync().platform == 'android') {
that.clientId1 = inf.clientid;
that.tokenType = 'android';
console.log(that.clientId1)
} else if (uni.getSystemInfoSync().platform == 'ios') {
that.clientId = inf.token;
that.tokenType = 'ios';
}
uni.onPush({
provider: that.provider[0],
success: e => {},
callback: e => {}
});
},
fail: function(err) {
uni.onPush({
provider: that.provider[0],
success: e => {},
callback: e => {}
});
}
});
},
fail: e => {

uni.subscribePush({
provider: that.provider[0],
success: function(res) {
uni.onPush({
provider: that.provider[0],
success: e => {},
callback: e => {}
});
},
fail: function(err) {
uni.onPush({
provider: that.provider[0],
success: e => {},
callback: e => {}
});
}
});
}
});

5.uni开发后台unipush配置中的"APPKEY", "APPID","MASTERSECRET",交予后端

标签:function,uniapp,console,success,unipush,provider,msg,uni,推送
来源: https://www.cnblogs.com/ysx1129/p/15769585.html