1.在vue 的index.html中js我是这么写的:
// 控制台输出日志
function outLog(msg) {
console.log(msg);
}
// 界面弹出吐司提示
function outLine(msg) {
mui.toast(msg);
}
var setTagsWithAlias = function () {
var tag1 = '.....'
var tag2 = ''
var tag3 = ''
var alias = '*****'
var tags = []
if (tag1) {
tags.push(tag1)
}
if (tag2) {
tags.push(tag2)
}
if (tag3) {
tags.push(tag3)
}
window.plus.Push.setTagsWithAlias(tags, alias)
}
var getRegistrationID = function () {
window.plus.Push.getRegistrationID(function (data) {
if (data.length != 0) {
outLine('getRegistrationID>>>>' + data)
}
})
}
var getLaunchAppCacheNotification = function () {
if (mui.os.android) {
window.plus.Push.getLaunchAppCacheNotification(function (data) {
if (data.alert) {
outLine('cache:' + data.alert)
}
})
}
}
var receiveNotification = function (event) {
var content
if (mui.os.ios) {
content = window.plus.Push.receiveNotification.aps.alert
} else {
outLine('receiveNotification---else')
content = window.plus.Push.receiveNotification.alert
}
outLine(content)
}
var openNotification = function () {
var content
if (mui.os.ios) {
content = window.plus.Push.openNotification.aps.alert
} else {
content = window.plus.Push.openNotification.alert
window.plus.Push.clearLaunchAppCacheNotification()
}
outLine(content)
vm.$router.replace({path: '/login/register'})
}
var receiveMessage = function () {
var msg
if (mui.os.ios) {
msg = window.plus.Push.receiveMessage.content
} else {
msg = window.plus.Push.receiveMessage.message
}
outLine(msg)
}
var onAliasAndTagsSet = function (event) {
var result = 'result code: ' + event.arguments.resultCode + ' '
result += 'tags: ' + event.arguments.tags + ' '
result += 'alias: ' + event.arguments.alias + ' '
mui.alert(result)
outLine(result)
}
var init = function () {
outLog('isInit:' + localStorage.getItem('isInit'))
outLine('isInit:' + localStorage.getItem('isInit'))
window.plus.Push.setDebugMode(true)
window.plus.Push.init()
getLaunchAppCacheNotification()
outLine('mui.os.android is ' + mui.os.android)
if (localStorage.getItem('isInit')) {
getRegistrationID()
} else {
localStorage.setItem('isInit', true)
}
}
document.addEventListener("plusready", init, false)
document.addEventListener('jpush.onGetRegistrationId', (rId) => {
console.log('registration id: ' + rId)
outLine('jpush::registration id: ' + rId)
localStorage.setItem("registrationId", rId)
// setTagsWithAlias()
}, false)
document.addEventListener("jpush.receiveMessage", receiveMessage, false)
document.addEventListener("jpush.receiveNotification", receiveNotification, false)
document.addEventListener("jpush.openNotification", openNotification, false)
document.addEventListener("jpush.setTagsWithAlias", onAliasAndTagsSet, false)
2.其中跟jpush之间的集成已完成,且能正常使用,接下来就是解析通知内容,跳转不同页面。
请看var openNotification =function(){}方法,其中比如我跳转注册页面,没有效果,请哪位帮忙指导一下,谢谢。
0 个回复