分享出去的小程序,新用户打开时候没有调用onLaunch?
发布于 5 年前 作者 mingzou 14759 次浏览 来自 官方Issues

没有调用onLaunch,导致没有调用wx.login结果无法获得首布局。

onLaunch: function(options) {
    console.log(options);
    var scene = decodeURIComponent(options.scene);
    if (scene.indexOf('@') != -1) {
      var arr = scene.split('@');
      if (arr.length >= 2)
        options.query.user_id = arr[1];
      if (arr.length >= 3)
        options.query.applet_id = arr[2];
    }
    this.globalData.share_data = options.query;
    this.onLogin();
    this.getAppBar();
  },
  onLogin() {
    try{
      // 登录
      wx.login({
        success: res => {
          this.globalData.code = res.code;
          // 获取用户信息
          wx.getSetting({
            success: res => {
              if (res.authSetting['scope.userInfo']) {
                // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
                wx.getUserInfo({
                  success: res => {
                    。。。。。
                    }, (data) => {
                      wx.reLaunch({
                        url: '/pages/user/register',
                      })
                    });
                  },
                  fail:res=>{
                    wx.reLaunch({
                      url: '/pages/user/register',
                    })
                  }
                })
              } else {
                wx.reLaunch({
                  url: '/pages/user/register',
                })
              }
            },
            fail: res => {
              wx.reLaunch({
                url: "/pages/user/register",
              })
            }
          })
        },
        timeout: res => {
          wx.reLaunch({
            url: "/pages/user/register",
          })
        },
        fail: res => {
          wx.reLaunch({
            url: "/pages/user/register",
          })
        }
      })
    }catch(e){
      wx.reLaunch({
        url: "/pages/user/register",
      })
    }
  },

按照如上逻辑 没有获取用户信息权限,肯定跳转到/pages/user/register,但是十个新用户 会出现一两个不跳转,一直在/pages/index/index,等待

if (this.userInfoReadyCallback) {
	this.userInfoReadyCallback(res);
}

因为我试过很多手机都没有出现,但是客户已经有好几个卡死主界面了,所以我怀疑是不是onLaunch没有调用。

求大神帮我看看!!!!!!!!!

回到顶部