uniapp 插件地址ext.dcloud.net.cn/plugin?id=7…
先在项目中引入插件 在app原生插件配置中选择jypush, 先用试用版的,(正式版需要十块钱 必须绑定包名)
HBuilder X配置极光推送的appid
在main.js 定义一个方法 挂载到全局
const setupJYJPush = () => {
console.log('setupJYJPush');
// #ifdef APP-PLUS
const jyJPush = uni.requireNativePlugin('JY-JPush');
//设置极光后台存储用户名作推送唯一标志
let userInfo = uni.getStorageSync('userInfo') || ''; //这里根据自己项目缓存的信息更改
if (userInfo != '') {
jyJPush.setJYJPushAlias({
userAlias: userInfo.mobile //将用户的手机号作为唯一标识传给极光后台,可以根据自己的项目需求更换
}, result => {
// console.log("result"+JSON.stringify(result)); //如果注册成功会在控制台 返回信息
// uni.showToast({
// icon: 'none',
// title: JSON.stringify(result)
// })
});
//接受消息 app程序在运行中 弹出到app窗口 一般不需要用到
jyJPush.addJYJPushReceiveNotificationListener(result=> {
console.log("result"+JSON.stringify(result));
// 监听成功后,若收到推送,会在result返回对应的数据;数据格式保持极光返回的安卓/iOS数据一致
// uni.showToast({
// icon: 'none',
// title: result.notificationContent,
// duration: 5000
// })
});
//x消息推送到通知栏 用户点击通知栏事件
jyJPush.addJYJPushReceiveOpenNotificationListener(result => {
// console.log("result"+JSON.stringify(result));
// uni.showModal({
// title:result.notificationTitle,
// content:JSON.stringify(result.notificationContent),// .notificationContent,
// success: function (res) {
// console.log(result.notificationExtras.id)
// console.log(res)
// },
// });
uni.navigateTo({
url: `/pages/index/message-detail?type=${JSON.parse(result.notificationExtras).id}`, //根据业务跳转到相应的页面 result.notificationExtras是后台返回的消息内容
});
uni.navigateBack
});
}
// #endif
};
Vue.prototype.$jpush = {
setupJYJPush
};
手机app登录完成之后调用 全局挂载的方法
this.$jpush.setupJYJPush();
真机调试 HBuilder 状态栏 运行=> 运行到手机或模拟器=> 制作自定义基座
可以选择公测证书
等待自定义基座打包完成后 再运行到手机上
打正式包需要购买,购买完成后 在记录里会有一条 在HBuilder切换正式版的插件
购买的插件不支持离线打包 只能在线打包