简单记录下开发极光推送遇到的问题
启动Hbuilder,在项目 选择manifest.json 找到 如下图步骤,选择极光推动官方插件
App模块配置勾选push推送,子项不需要勾选
此处只简单介绍前端的引用和功能。如要将极光推送管理集成到自己的管理平台,可以配合后端联调
关于各个设备中的appid 可以通过极光后台配置后获取到
APP.vue 引入JG-JPush
// #ifdef APP-PLUS
let jpushModule = uni.requireNativePlugin("JG-JPush");
// #endif
onLaunch () {
// #ifdef APP-PLUS
// 用户是否同意隐私协议后再初始化
// ios 没有隐私协议弹框 需要时自定义
// 上架的时候部分厂商需要先同意隐私协议才能调用相关Api,
const self = this
if (uni.getSystemInfoSync().platform !== "ios") {
if(plus.runtime.isAgreePrivacy()){
console.log('同意隐私协议')
// initApp();
// 初始化极光SDK
self.initJPushService()
}
} else {
// initApp();
// 初始化极光SDK
self.initJPushService()
}
//#endif
},
methods:{
// 初始化极光推送相关服务
initJPushService() {
const self = this
jpushModule.initJPushService();
// 开启debug模式
jpushModule.setLoggerEnable(true);
// 锁定屏幕方向为 "portrait-primary",即主竖直方向
plus.screen.lockOrientation("portrait-primary");
// 设置别名
jpushModule.setAlias({
'alias': uni.getStorageSync('userId') +'' || 1, //'this.lxzl.getUserInfo().userId + ''',
'sequence': 1
})
jpushModule.addConnectEventListener(result => {
let connectEnable = result.connectEnable
uni.$emit('connectStatusChange', connectEnable)
});
// result 后端推动给你得内容在这儿能拿到
jpushModule.addNotificationListener(result => { //极光推送的消息通知回调
jpushModule.setBadge(0); // 修改角标
plus.runtime.setBadgeNumber(0);
let notificationEventType = result.notificationEventType
let msgId = result.extras && result.extras.id;
let link = result.extras && result.extras.link
// 点击事件 点击消息跳转到指定页面
if (notificationEventType == 'notificationOpened') {
if(link) {
console.log('跳转到指定的页面')
uni.navigateTo({
url: link
})
} else {
console.log('跳转到消息详细页面',)
uni.navigateTo({
url: `/pages/mine/message_info?id=${msgId}`
});
}
}
});
if (uni.getSystemInfoSync().platform !== "ios") {
jpushModule.isPushStopped(res => {
console.log('res', res)
const { code } = res
// code 0已停止推送 1未停止推送
console.log(res, '安卓连接状态');
})
}
}
在开发过程中可以通过极光后台做推送测试
该功能看似内容不多,但是在开发过程中遇到过很多问题,
后面开发完成后打包,遇到无法上架问题 主要是隐私协议问题。 隐私协议声明,可以参考这个隐私合规问题处理参考:docs.jiguang.cn/jpush/pract…
好在极光客服很配合 最后 不停的反馈。。。
第二次驳回
第三次驳回
至此完成最终开发!!!