添加消息推送云函数、消息处理为后续的消息通知做准备
This commit is contained in:
47
App.vue
47
App.vue
@ -29,19 +29,55 @@
|
||||
// uni.clearStorageSync();
|
||||
//以上代码仅在开发时使用,否则会出现不可预知的问题。
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
// #ifdef APP|APP-PLUS
|
||||
|
||||
bleTool.getBleTool();
|
||||
|
||||
var appid = plus.runtime.appid;
|
||||
console.log('应用的 appid 为:' + appid);
|
||||
|
||||
|
||||
uni.getPushClientId({
|
||||
success(res) {
|
||||
console.log("推送信息:", res);
|
||||
uni.setStorageSync('push_cid', res.cid);
|
||||
},
|
||||
fail(err) {
|
||||
console.error(err)
|
||||
}
|
||||
});
|
||||
if(!uni.setAppBadgeNumber){//兼容鸿蒙的写法
|
||||
uni.setAppBadgeNumber=plus.runtime.setBadgeNumber;
|
||||
}
|
||||
uni.onPushMessage((res) => {
|
||||
console.log("收到推送消息:", res); //监听推送消息
|
||||
if(res.type=='click'){
|
||||
//将App角标设置为0,清空app在消息中心的所有消息
|
||||
uni.setAppBadgeNumber(0);
|
||||
plus.push.clear();
|
||||
return;
|
||||
}
|
||||
uni.createPushMessage({
|
||||
title: res.data.title,
|
||||
content: res.data.content,
|
||||
payload:res.data.payload
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// #endif
|
||||
},
|
||||
onShow: function() {
|
||||
console.log('App Show');
|
||||
|
||||
|
||||
//将检查更新换到onshow,因为苹果用户喜欢一直挂着
|
||||
uni.getSystemInfo({
|
||||
success: function(res) {
|
||||
if (res.uniPlatform == 'app') {
|
||||
bleTool.getBleTool();
|
||||
|
||||
let appid = plus.runtime.appid;
|
||||
if (appid !== 'HBuilder') {
|
||||
console.log("appid=", appid);
|
||||
@ -55,7 +91,7 @@
|
||||
console.log('App Hide');
|
||||
},
|
||||
onError(ex) {
|
||||
console.error("出现了未知的异常",ex);
|
||||
console.error("出现了未知的异常", ex);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -152,7 +188,8 @@
|
||||
.displayNone {
|
||||
display: none !important;
|
||||
}
|
||||
.visibilityHidden{
|
||||
|
||||
.visibilityHidden {
|
||||
visibility: hidden !important;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user