收藏
回答

ios中wx.onGetWifiList不进入回调?

ios iPhone 6,系统版本是11.1.2,微信版本是:7.0.15。在getWifiList 进入后台wifi列表后,再次返回到小程序界面,wx.onGetWifiList没有进行
回调,在iPhoneX手机中试的wx.onGetWifiList可以正常回调


wx.getWifiList({
      success(res) => {
        console.log("487:" + JSON.stringify(res));
        log.info("wifiList:"+JSON.stringify(res));
      },
      fail(err) {
        console.error(err);
        log.error("获取wifi列表失败:"+err.errCode);
      }
    })
    wx.onGetWifiList((res) => {
      console.log("监听到的wifi列表aaaaa:");
      that.data.apWifi = [];
      const wifiList = res.wifiList;
      log.info("监听到的wifi数量:"+wifiList.length);
      log.info("监听wifi列表:"+res.wifiList);
      for (var i = 0; i < wifiList.length; i++) {
        var ssid = wifiList[i].SSID;
        if (ssid.indexOf("zcy_"+app.globalData.wifiModeId) > -1) {
          that.data.apWifi.push(wifiList[i]);
        }
      }
      if (that.data.apWifi.length>0) {
        var apList=that.data.apWifi;
        that.data.apWifi = apList.sort(that.compare('signalStrength',false));
        that.data.apConnectSuc = true;
        console.log("热点列表"+JSON.stringify(that.data.apWifi));
        clearTimeout(that.data.apTimeout);
        log.info("监听到ap列表:"+JSON.stringify(that.data.apWifi));
        that.setData({
          orderAp:that.data.apWifi[0].SSID
        })
        if(that.data.isIos) {
          console.log("热点:"+that.data.orderAp);
          log.info("ios连接ap:"+that.data.orderAp);
          wx.setWifiList({
            wifiList: [{
              SSID: that.data.orderAp,
              password''
            }],
            success:function(res){
              that.data.iosHide = true;
              console.log("ios-setWifiList:"+JSON.stringify(res));
              log.info("ios-setWifiList1:"+JSON.stringify(res.errMsg))
              that.sendFun();
            }
          })
        } else {
          if(!that.data.isApSuc){
            that.data.isApSuc = true;
            log.info("Android-conct-Ap:"+that.data.orderAp);
            wx.connectWifi({
              SSID: that.data.orderAp,
              password'',
              successfunction (res{
                console.log("ap已连接至" + that.data.orderAp);
                log.info("Androdi-connect-ap-fir"+JSON.stringify(res.wifi.SSID));
                setTimeout(function(){
                  that.sendFun();
                },2000)
              },
              failfunction (err{
                console.log("第一次连接热点失败"+err.errCode);
                log.error("第一次安卓连接热点失败"+err.errCode);
              }
            })
          }
        }
      } else {
        clearTimeout(that.data.apTimeout);
        log.info("未监听到ap重新获取wifi列表");
        if(that.data.isIos){
          wx.setWifiList({
            wifiList: []
          })
        }
        if(!that.data.isIos){
          that.data.apTimeout=setInterval(function () {
            wx.getWifiList({
              success(res) => {
                // console.log("定时获取wifi列表:" + JSON.stringify(res));
              },
              fail(err) {
                console.error(err);
              }
            })
          }, 2000)
        }
      }
    })
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签