收藏
回答

wx.openSetting()方法无法正常调用

问题模块 框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
API和组件 小程序 Bug wx.openSetting() 客户端 7.0.4 2.7.0

我通过一个checkbox的bindtap事件来调用wx.openSetting()方法,发现微信开发者工具的模拟器显示


然后在客户端体验版中调试,是这个问题:

根据wx.openSetting()接口的调整,官方给出的说法是通过bindtap调用的showModal()方法也可以打开窗口,我的代码如下:

<checkbox color="#333333" bindtap="userAuthorizationFunc"/>
userAuthorizationFunc: function(responseTemp) {
    wx.getSetting({
      success:function(res){
        if(res.authSetting['scope.userInfo']){//已经授权时不打开弹窗
          console.log("当前用户授权状态:",res);
        }else{//尚未授权时打开弹窗
          wx.showModal({
            title: '授权申请',
            content: '我们请求您对本小程序进行使用授权',
            showCancel: true,
            confirmText: "进行授权",
            confirmColor: "#2d303a",
            cancelText: "取消",
            cancelColor: "#E00000",
            success: function (res) {
              //点击“进行授权”按钮,引导用户进行小程序授权
              if (res.confirm) {
                console.log("User Click Confirm Button!\n");
                //打开用户授权设置页
                wx.openSetting({
                  success: function (res) {
                    console.log("OpenSetting Function call success!Response: ", res);
                  },
                  fail: function (res) {
                    console.log("OpenSetting Function call fail!Response: ", res);
                  },
                  complete: function (res) {
                    console.log("OpenSetting Function call complete.Response: ", res);
                  }
                });
              }
              //点击“取消”按钮,则Toast提示用户然后返回index page
              //Toast显示2.5秒,Toast显示的同时启动计时器,Toast显示结束后等待0.2秒,然后relaunch至index page
              else if (res.cancel) {
                console.log("User Click Cancel Button!\n");
                wx.showToast({
                  title: "我们会不断改进我们的产品来提高用户体验的友好度。感谢您的支持!",
                  icon: 'none',
                  duration: 2500,
                  mask: true, //开启透明蒙层(并且防止触摸穿透)
                  success: function (res) {
                    console.log("User Reject Authorization.Call Toast Success!Response: ", res);
                    setTimeout(function (responseTemp) {
                      console.log("Use Relaunch Prepare……");
                      wx.reLaunch({
                        //After update URL to Index dir
                        url: '../index/index',
                        success: function (res) {
                          console.log("Relaunch function Success!Response: ", res);
                          wx.hideToast();
                        },
                        fail: function (res) {
                          console.error("Relaunch function Failed!Response: ", res);
                        },
                        complete: function (res) {
                          console.info("Relaunch function complete!Response: ", res);
                        },
                      });
                    }, 2700);
                  },
                  fail: function (res) {
                    console.error("User Reject Authorization.Call Toast Fail!Response: ", res);
                  },
                  complete: function (res) {
                    console.info("User Reject Authorization.Call Toast Complete!Response: ", res);
                  }
                });
 
              }
            },
            fail: function (res) {
              console.error("User Authorization Modal function call failed!Response: ", res);
            },
            complete: function (res) {
              console.info("User Authorization Modal function call complete!Response: ", res);
            }
          });
        }
      },
    });
     
  }

但是当我先通过一个Button触发获取用户信息wx.getUserInfo()接口后这个wx.openSetting接口才可以正常调用,但是官方给出的回复是:


请问如何解决?

最后一次编辑于  05-27  (未经腾讯允许,不得转载)
回答关注问题邀请回答
收藏

1 个回答

  • 拾忆
    拾忆
    05-27

    你截图的是去年9月的了,早改了,现在是必须要触发后才能在wx.openSetting()打开的页面里看到需要用的权限。

    05-27
    赞同
    回复 7
    • Vivien_Dennis
      Vivien_Dennis
      05-27

      现在只能是bindtap触发wx.openSetting()接口了?我这种通过bindtap触发wx.showModal()后再调用wx.openSetting()接口是不行了吗?

      05-27
      回复
    • 拾忆
      拾忆
      05-27

      你先触发授权提示框,用户点授权或拒绝后,再去wx.openSetting()里看看。

      05-27
      回复
    • Vivien_Dennis
      Vivien_Dennis
      05-27回复拾忆

      先通过bindtap调用wx.authorize(),然后再调用wx.openSetting()接口?

      05-27
      回复
    • 拾忆
      拾忆
      05-27回复Vivien_Dennis

      不是,是先调用比如位置授权或者登录授权,如果用户拒绝再调用wx.openSetting()

      05-27
      回复
    • Vivien_Dennis
      Vivien_Dennis
      05-27回复拾忆

      请问是调用哪个接口?调用wx.login()接口还是其他?

      05-27
      回复
    查看更多(2)