vue + apicloud 实现极光推送
- 在极光推送官网申请appkey,并绑定应用包名
- 在apicloud上添加极光推送模块,配置config.xml文件
- 在index.html页面初始化ajpush注意:apicloud代码需要写在apiready = function () {} 里面注意:apicloud代码需要写在apiready = function () {} 里面
- 点击推送消息后跳转相对应的页面
PushOnClick() //监听极光推送点击
//点击推送接收回调事件处理
function PushOnClick() {
if (api.systemType == "ios") {
api.addEventListener({
name: 'noticeclicked'
}, function (ret, err) {
// console.log(JSON.stringify(ret))
var str_info = ret.value.extra.jumpinfo;
str_info = str_info.replace(/'/g, '"')
var info = JSON.parse(str_info)
// console.log(info.type + ":" + info.id)
click_jump(info.type, info.id)
clearAJpush()
})
} else {
api.addEventListener({
name: 'appintent'
}, function (ret, err) {
console.log(JSON.stringify(ret))
var str_info = ret.appParam.ajpush.extra.jumpinfo;
str_info = str_info.replace(/'/g, '"')
var info = JSON.parse(str_info)
// console.log(info.type + ":" + info.id)
click_jump(info.type, info.id)
clearAJpush()
})
}
}
// 清除推送
function clearAJpush() {
var ajpush = api.require('ajpush');
ajpush.setBadge({
badge: 0
});
var param = { id: -1 };
ajpush.clearNotification(param, function (ret) {
if (ret.status == 1) {
// console.log("清除推送成功")
}
});
}
//极光推送跳转
function click_jump(type, id) {
clearAJpush()
// alert(window.location.href.substr(0, window.location.href.indexOf("#") + 2))
// alert(window.location.href.substr(0, window.location.href.indexOf("#") + 2))
if (type == 2) { 优惠卷
api.openWin({
name: 'Coupon',
url: window.location.href.substr(0, window.location.href.indexOf("#") + 2) + 'coupon',
});
} else if (type == 3) { //商品详情
api.openWin({
name: 'Detail',
url: window.location.href.substr(0, window.location.href.indexOf("#") + 2)+ 'detail?ProId=' + id,
});
} else if (type == 4) { //店铺
api.openWin({
name: 'Shop',
url: window.location.href.substr(0, window.location.href.indexOf("#") + 2) + 'shop?StoreId=' + id,
});
} else if (type == 5) { //平台活动
api.openWin({
name: 'Specialarea',
url: window.location.href.substr(0, window.location.href.indexOf("#") + 2) + 'specialarea?Value=' + id,
});
} else { //首页
api.openWin({
name: 'Home',
url: window.location.href.substr(0, window.location.href.indexOf("#") + 2) + 'main/home',
});
}
}
扫码加q群