用uniappx开发的软件,想要接入离线推送,在后台已经填写了AppID, AppKey, AppSecret,MasterSecret,但是在oppo手机上无法接受到离线推送,只有打开app的时候才会出现推送
厂商包没打包进去
如何解决?
onLaunch: function () {
// 检查本地隐私政策同意状态
const privacyStatus = StorageUtil.getPrivacyAgreeStatus()
console.log("隐私政策状态 =", privacyStatus)
// 如果用户未设置隐私政策状态,显示隐私政策弹窗
if (privacyStatus == null) {
uni.openDialogPage({
url: "/pages/privacy/privacy"
})
}
loadUserInfoFromStorage()
if (privacyStatus == true) {
initPushListener()
}
// 监听隐私同意事件,收到后再初始化推送
uni.$on('privacy-agreed', () => {
initPushListener()
uni.$off('privacy-agreed')
})
},
function initPushListener(): void {
uni.getPushClientId({
success(res) {
console.log('推送 CID =', res.cid)
},
})
uni.setAppBadgeNumber(0)
uni.onPushMessage((res) => {
// 通知点击(离线/在线通知栏点击)
if (res.type == 'click') {
const payloadObj = JSON.parseObject(JSON.stringify(res.data.payload))
let urlVal: string = tempUrl
if (payloadObj != null) {
const plUrl = payloadObj['url'] as string | null
if (plUrl != null && plUrl.length > 0) {
urlVal = plUrl
}
}
if (urlVal.length > 0) {
toPushUrl(urlVal)
}
}
// 在线消息到达
if (res.type == 'receive') {
if (res.data.title != null && res.data.content != null) {
const payloadObj2 = JSON.parseObject(JSON.stringify(res.data.payload))
const incomingUrl = payloadObj2 != null ? payloadObj2['url'] as string | null : null
tempUrl = incomingUrl ?? ""
const titleStr = res.data.title as string | null
const contentMaybe = res.data.content as string | null
const contentStr = contentMaybe ?? ""
uni.createPushMessage({
title: titleStr,
content: contentStr,
payload: res.data.payload
})
}
}
})
}
这是我在app.uvue的onLaunch中初始化推送的代码