unipush+个推实现消息推送

1.注册个推平台的帐号个推,专业的数据智能服务商-为垂直领域提供数据智能解决方案

2.应用列表中选择新增应用/服务

3.填写下应用信息4.创建好应用后在manifest.json中的sdkConfigs配置上写入appid、appkey、appsecret

复制代码
           "sdkConfigs" : {
                "ad" : {},
                "push" : {
                    "igexin" : {
                        "appid" : "你的appid",
                        "appkey" : "你的appkey",
                        "appsecret" : "你的appsecret"
                    }
                }
            },

配置好后,在manifest.json中勾选Push模块(不勾选uniPush1.0和uniPush2.0)

5.登录方法中,写入获取cid的方法

复制代码
let userCid = ''
let pinf = plus.push.getClientInfo();
userCid = pinf.clientid;
console.log(userCid ,'userCid');

6.在app中写入监听推送方法

复制代码
	uni.onPushMessage(res=>{
                    //接收消息
					if(res.type=='receive'){
						uni.createPushMessage({
							title:res.data.payload.title,
							content:res.data.payload.body,
							payload:res.data.payload
						})
                    //这里我们使用了自定义的提示音
						const innerAudioContext = uni.createInnerAudioContext();
							innerAudioContext.autoplay = true;
							const filePath = '音频地址';
							innerAudioContext.src = filePath;
							innerAudioContext.onPlay(() => {
								console.log('开始播放');
							});
						innerAudioContext.play();
                    //点击后
					}else if(res.type=='click'){
                        跳转到首页
						uni.navigateTo({
							url:'/pages/index/index'
						})
					}
					
	
				});

前端部分 仅供参考,欢迎各位大佬指导!后续会补充离线推送

相关推荐
崔庆才丨静觅1 小时前
hCaptcha 验证码图像识别 API 对接教程
前端
passerby60612 小时前
完成前端时间处理的另一块版图
前端·github·web components
掘了2 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
崔庆才丨静觅2 小时前
实用免费的 Short URL 短链接 API 对接说明
前端
崔庆才丨静觅3 小时前
5分钟快速搭建 AI 平台并用它赚钱!
前端
七夜zippoe3 小时前
CANN Runtime任务描述序列化与持久化源码深度解码
大数据·运维·服务器·cann
盟接之桥3 小时前
盟接之桥说制造:引流品 × 利润品,全球电商平台高效产品组合策略(供讨论)
大数据·linux·服务器·网络·人工智能·制造
崔庆才丨静觅3 小时前
比官方便宜一半以上!Midjourney API 申请及使用
前端
Moment3 小时前
富文本编辑器在 AI 时代为什么这么受欢迎
前端·javascript·后端
崔庆才丨静觅3 小时前
刷屏全网的“nano-banana”API接入指南!0.1元/张量产高清创意图,开发者必藏
前端