收藏
回答

wx.connectWifi 连接wifi失败?

华为,荣耀10,oppoR15,苹果12,华为nova6,Nova7, 都连接失败
wx.connectWifi({
      SSID: wifiName,
      password: wifiPassword,
      success(res) => {
        wx.hideLoading()
        if (that.data.platform == 'ios') { // 是否是IOS可通过提前调用getSystemInfo知道
         
          that.setData({
            isConnecttrue
          })
          // 连接成功
          wx.showModal({
            title'提示',
            content'WiFi连接成功',
            confirmText'确定',
            showCancel'false',
            success(res) {
              if (res.confirm) {
                
              }
            }
          })
         
        } else {
          that.setData({
            isConnecttrue
          })
          // 连接成功
          wx.showModal({
            title'提示',
            content'WiFi连接成功',
            confirmText'确定',
            showCancel'false',
            success(res) {
              if (res.confirm) {
                


              }
            }
          })
        }
        wx.stopWifi({
          success(res) {
            console.log(res.errMsg)
          }
        })
       
      },
      fail(res) => {
        wx.hideLoading()
        switch (res.errCode) {
          case 1200:
            wx.showModal({
              title'提示',
              content'未先调用startwifi接口',
              success(res) {
                if (res.confirm) {
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
            break
          case 12001:
            wx.showToast({
              title'当前系统不支持相关能力',
            })
            break
          case 12002:
            wx.showModal({
              title'提示',
              content'密码错误',
              success(res) {
                if (res.confirm) {
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
            break
          case 12003:
            wx.showModal({
              title'提示',
              content'连接超时',
              success(res) {
                if (res.confirm) {
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
            break
          case 12004:
            wx.showModal({
              title'提示',
              content'重复连接wifi',
              success(res) {
                if (res.confirm) {
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
            break
          case 12005:
            wx.showModal({
              title'提示',
              content'请打开WiFi开关',
              success(res) {
                if (res.confirm) {
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
            break
            case 12006:
              wx.showModal({
                title'提示',
                content'Android 特有,未打开 GPS 定位开关',
                success(res) {
                  if (res.confirm) {
                    that.autoConnected(wifiName, wifiPassword)
                  } else if (res.cancel) {
                    console.log('用户点击取消')
                  }
                }
              })
              break
              case 12007:
                wx.showModal({
                  title'提示',
                  content'用户拒绝授权链接 Wi-Fi',
                  success(res) {
                    if (res.confirm) {
                     
                    } else if (res.cancel) {
                      console.log('用户点击取消')
                    }
                  }
                })
                break
              case 12008:
                wx.showToast({
                  title'无效 SSID',
                })
                break
              case 12009:
                wx.showToast({
                  title'系统运营商配置拒绝连接 Wi-Fi',
                })
                break
              case 12010:
                wx.showModal({
                  title'提示',
                  content'系统其他错误,需要在 errmsg 打印具体的错误原因',
                  success(res) {
                    if (res.confirm) {
                     
                    } else if (res.cancel) {
                      console.log('用户点击取消')
                    }
                  }
                })
                break
        }



      }
    })
  },
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容