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'
						})
					}
					
	
				});

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

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值