uniapp的app端推送功能,不使用unipush

1:推送功能使用htmlPlus实现:地址HTML5+ API Reference (html5plus.org)

效果图:

代码实现:

javascript 复制代码
<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中有相关方法,如果获取到的值是没有打开的状态就要显示弹框询问是否打开通知权限,点击确定就跳转到应用权限页

相关推荐
阿常115 小时前
uni-app基础拓展
前端·javascript·uni-app
智驾7 小时前
uniapp,自绘仪表盘组件(基础篇)
uni-app·仪表
三天不学习16 小时前
uniapp x 学习之 uts 语言快速入门
学习·uni-app
人民广场吃泡面17 小时前
UniApp 运行的微信小程序如何进行深度优化
微信小程序·小程序·uni-app
程序员大澈18 小时前
4个 Vue 路由实现的过程
javascript·vue.js·uni-app
T-shmily21 小时前
Hbuilder X开发微信小程序:利用uni-app和uview UI框架创建项目详细步骤
微信小程序·uni-app
JAVA叶知秋1 天前
完美解决uni-app打开页面无法自动播放视频的问题
前端·uni-app·音视频
狼性书生1 天前
uniapp实现的个人中心页面(仿小红书)
uni-app·vue
明耀2 天前
uniapp或者vue 使用serialport
前端·vue.js·uni-app