uniapp集成个推

个推消息分为 通知消息透传消息

客户端个推通知个推透传厂商通知厂商透传
android支持支持支持不支持
ios不支持支持支持不支持

在线走个推通道,离线走厂商通道
uniapp官方文档:https://ask.dcloud.net.cn/article/35622
android厂商通道配置:https://docs.getui.com/getui/mobile/vendor/vendor_open/
ios推送证书配置:https://docs.getui.com/getui/mobile/ios/apns/

在这里插入图片描述
重点注意 intent 的生成格式

//一般格式
intent://io.dcloud.unipush/?#Intent;scheme=unipush;launchFlags=0x4000000;component=com.taobao.taobao/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=测试标题;S.content=测试内容内容;S.payload={\"stitle\":\"个推提交的单据需要你处理\",\"type\":102,\"depid\":2986,\"num\":132};end

//说明
com.taobao.taobao :换成自己的包名
S.title、S.content、S.payload都是自定义内容
<script>
	export default {
		globalData: {
	 		phoneSystem: '', //手机系统型号
		},
		onLaunch() {
			this.globalData.phoneSystem = systemInfo.platform;
			this.pushMessage();
		},
		methods: {
			pushMessage() {
				const _self = this
				const _handlePush = function(item) {
					//未登录拦截
					if (!_self.$store.state.vuex_token) {
						console.log('未登录拦截');
						uni.reLaunch({
							url: '/pages/public/login'
						})
						return;
					}

					//更新app角标
					_self.$store.dispatch('getMessageNumber')
					
					//业务逻辑处理
				}

				// #ifdef APP-PLUS
				let timer = false;
				//点击消息
				plus.push.addEventListener('click', function(message) {
					console.log('*********** click start ************')
					console.log(message)
					console.log('*********** click end **************')

					let payload = message.payload;
					if (_self.globalData.phoneSystem.toUpperCase() == 'IOS' && message.aps == null) {
						payload = JSON.parse(message.payload)
					}
					clearTimeout(timer);
					timer = setTimeout(() => {
						_handlePush(payload)
					}, 1500)
				})

				// 透传消息
				plus.push.addEventListener('receive', function(message) {
					console.log('*********** receive start ************')
					console.log(message);
					console.log('*********** receive end **************')

					if (_self.globalData.phoneSystem.toUpperCase() == 'IOS' &&
						message.type == 'receive') {
						plus.push.createMessage(message.content, message.payload, {
							title: message.title
						})
					}
				})
				// #endif 
			},
			
	}
</script>

说明

  1. 目前uniapp的角标好像只支持 ios 和 华为,高版本的小米系统不支持,角标计数需要配置华为的厂商参数 https://docs.getui.com/getui/server/rest_v2/third_party/
  2. 部分华为手机收到推送消息后,若没配置,则会默认显示个推的图标,配置步骤参考 https://ask.dcloud.net.cn/article/35537
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值