unipush的使用及注意事项

本文详细介绍了在uni-app中如何使用cunipush进行消息推送的处理,包括onLaunch()函数内的初始化设置,以及用户点击推送消息和接收消息时的事件监听方法,帮助开发者实现用户点击通知后的页面跳转和模态提示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

传送门 >> ​​​​​​cunipush的使用及注意事项 - huihuihero - 博客园 (cnblogs.com)

onLaunch() {
	// console.log('初始化完成了(只触发一次)');
	// #ifdef APP-PLUS  
	const _self = this;  
	const _handlePush = function(message) {
		// console.log(message)
		if(message.payload){
			uni.navigateTo({
				url: message.payload
			});
		}
	};  
        const _handleRemind = function(message) {
		if(message.content){
			uni.showModal({
				title: '温馨提示',
				content: message.content,
				success: function (res) {
					if (res.confirm) {
						if(message.payload){
							uni.navigateTo({
								url: message.payload
							});
						}
					} else if (res.cancel) {
							
					}
				}
			});
		}
	};  
	plus.push.addEventListener('click', _handlePush);  //用户点击推送消息事件:一般在App后台运行时(消息通过厂商方式以通知形式在通知栏送达),然后用户点击消息后触发此事件
	plus.push.addEventListener('receive', _handleRemind);  //用户接收到推送消息事件:一般在用户正在使用App时(消息通过个推方式送达),用户直接在App内接收到消息并触发此事件
	// #endif  
},

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值