vue + apicloud 实现极光推送

  1. 在极光推送官网申请appkey,并绑定应用包名
  2. 在apicloud上添加极光推送模块,配置config.xml文件在这里插入图片描述
  3. 在index.html页面初始化ajpush注意:apicloud代码需要写在apiready = function () {} 里面在这里插入图片描述注意:apicloud代码需要写在apiready = function () {} 里面
  4. 点击推送消息后跳转相对应的页面
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群
在这里插入图片描述

Logo

加入社区!打开量化的大门,首批课程上线啦!

更多推荐