You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.7 KiB
64 lines
1.7 KiB
<script>
|
|
export default {
|
|
onLaunch: () => {
|
|
// 1 判断手机权限 , 如果没有权限就去设置
|
|
//#ifdef APP-PLUS
|
|
checkNotificationAuthorized();
|
|
//#endif
|
|
|
|
// 2 获取客户端推送标识信息 cid , 必须要获取到cid后才能接收推送信息
|
|
uni.getPushClientId({
|
|
success: (res) => {
|
|
// 将获取到的cid存起来,方便其它页面从缓存中获取
|
|
uni.setStorageSync('cid',res.cid)
|
|
console.log('客户端推送标识:', res.cid)
|
|
}
|
|
})
|
|
|
|
// 3 启动监听推送消息事件
|
|
uni.onPushMessage(res => {
|
|
const { type, data } = res
|
|
console.log('"click"-从系统推送服务点击消息启动应用事件;', res);
|
|
if (type == 'click') {
|
|
console.log('"click"-从系统推送服务点击消息启动应用事件;', res);
|
|
if (data?.payload?.type == 1) {
|
|
uni.reLaunch({
|
|
url: '/pages/index/index'
|
|
});
|
|
} else {
|
|
uni.reLaunch({
|
|
url: '/pages/users/order/index'
|
|
});
|
|
}
|
|
}
|
|
if (type == 'receive') {
|
|
console.log('"receive"-应用从推送服务器接收到推送消息事件', res);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
// 检查app是否开启了通知权限 安卓苹果通用
|
|
function checkNotificationAuthorized() {
|
|
const notificationAuthorized = uni.getAppAuthorizeSetting().notificationAuthorized
|
|
if (notificationAuthorized !== 'authorized') {
|
|
uni.showModal({
|
|
title: '通知权限',
|
|
content: '您还没有开启通知权限,无法接受到消息通知,请前往设置!',
|
|
confirmText: '去设置',
|
|
showCancel: false,
|
|
success:(res) => {
|
|
if (res.confirm) uni.openAppAuthorizeSetting()
|
|
}
|
|
});
|
|
}
|
|
}
|
|
</script>
|
|
<style>
|
|
/* #ifdef APP-PLUS || H5 */
|
|
page{
|
|
background-color: #f5f5f5;
|
|
}
|
|
/* #endif */
|
|
|
|
</style>
|
|
|