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>
说明
- 目前uniapp的角标好像只支持 ios 和 华为,高版本的小米系统不支持,角标计数需要配置华为的厂商参数 https://docs.getui.com/getui/server/rest_v2/third_party/
- 部分华为手机收到推送消息后,若没配置,则会默认显示个推的图标,配置步骤参考 https://ask.dcloud.net.cn/article/35537
更多推荐
已为社区贡献4条内容
所有评论(0)