uniapp 极光推送插件使用

271 阅读1分钟

下面两个插件都要放上

极光推送插件 JPush

极光推送插件 JCore

上面两个需要配置包名,配置方式如下

image.png

image.png

然后 去极光推送官网 配置应用信息,配置应用

uniapp中 manifest.json 文件配置

image.png

APP.vue中设置,直接放到 页面周期外部

<script>
// #ifdef APP-PLUS
const JPushInterface = uni.requireNativePlugin("JG-JPush");
JPushInterface.initJPushService(); //初始化极光推送服务
JPushInterface.addTagAliasListener((result) => {
  uni.showToast({
    icon: "none",
    title: JSON.stringify(result),
    duration: 3000,
  });
});
JPushInterface.addNotificationListener((result) => {
  console.log("点击通知:", result);
  // result.extras 包含自定义参数
  // result.notificationEventType === "notificationOpened" 
  // 判断是否点击,如果点击 返回 notificationOpened
  // 如果收到通知,但是不点击,返回  notificationArrived
  if (
    result.extras &&
    result.extras.url &&
    result.notificationEventType === "notificationOpened"
  ) {
    console.log("addTagAliasListener", result);
    uni.navigateTo({
      url: result.extras.url + "",
    });
  }
});
// #endif

export default {
    data() {},
    onLoad() {},
    onShow() {}
}
</script>

在需要切换 tags 或 alieas 的地方切换,即可,不要再次进行初始化等操作