1:推送功能使用htmlPlus实现:地址HTML5+ API Reference (html5plus.org)
效果图:
代码实现:
<template>
<view class="content">
<view class="text-area">
<button @click="createMsg">本地消息</button>
</view>
<button @click="openquanxian">跳转系统授权管理页</button>
<button @click="getquanxian">获取 APP 授权设置</button>
</view>
</template>
<script setup>
import {
ref,
onMounted,
nextTick
} from 'vue';
onMounted(() => {
})
const openquanxian = () => {
uni.openAppAuthorizeSetting({
success(res) {
console.log(res)
}
})
}
const getquanxian = () => {
let info = uni.getAppAuthorizeSetting()
console.log('log', info);
}
// #ifdef APP-PLUS
let ClientInfo = ref()
let AllMessage = ref()
const createMsg = () => {
plus.push.createMessage('我是一条本地消息', '', {
title: 'xxx科技',
})
ClientInfo.value = plus.push.getClientInfo()
console.log('log', ClientInfo.value);
AllMessage.value = plus.push.getAllMessage()
console.log('log', AllMessage.value);
// plus.push.setAutoNotification(true);
}
plus.push.addEventListener('click', function(success) {
console.log('logsss', success);
});
// #endif
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
请注意要实现消息推送功能,前提是应用的通知权限要打开
以上代码已实现从应用内跳到应用权限页,在实际工作中用户刚打开应用就要判断应用的通知权限是否打开,uniapp中有相关方法,如果获取到的值是没有打开的状态就要显示弹框询问是否打开通知权限,点击确定就跳转到应用权限页