wifi API 连接指定wifi 总是超时错误
- 当前 Bug 的表现(可附上截图)[图片] - 预期表现 连接成功或者连接失败 使用mpvue 搭建的环境 - 复现路径 mpvue 搭建环境即可 - 提供一个最简复现 Demo [代码]<template>[代码][代码] [代码][代码]<div>[代码][代码] [代码][代码]<button @click=[代码][代码]"startLocalServiceDiscovery"[代码][代码]>开始搜索</button>[代码][代码] [代码][代码]<button @click=[代码][代码]"stopLocalServiceDiscovery"[代码][代码]>停止搜索</button>[代码] [代码] [代码][代码]<button @click=[代码][代码]"startWifi"[代码][代码]>开启Wifi 获取</button>[代码][代码] [代码][代码]<button @click=[代码][代码]"getWifiList"[代码][代码]>获取Wifi 列表</button>[代码][代码] [代码][代码]<!-- <input v-model=[代码][代码]"pass"[代码] [代码]type=[代码][代码]"text"[代码] [代码]value=[代码][代码]"请输入密码"[代码][代码]> -->[代码][代码] [代码][代码]<input class=[代码][代码]"i-input"[代码] [代码]v-model=[代码][代码]"pass"[代码] [代码]placeholder=[代码][代码]"请输入密码"[代码][代码]>[代码][代码] [代码][代码]<ul v-[代码][代码]if[代码][代码]=[代码][代码]"wifiLists.length >0"[代码][代码]>[代码][代码] [代码][代码]<li class=[代码][代码]"item"[代码] [代码]v-[代码][代码]for[代码][代码]=[代码][代码]"(item, index) in wifiList"[代码] [代码]:key=[代码][代码]"index"[代码][代码]>[代码][代码] [代码][代码]wifi名称 :{{ item.SSID}}[代码][代码] [代码][代码]<button @click=[代码][代码]"selecedItem(index)"[代码] [代码]style=[代码][代码]"width=20px"[代码][代码]>选择</button>[代码][代码] [代码][代码]</li>[代码][代码] [代码][代码]</ul>[代码][代码] [代码][代码]</div>[代码][代码]</template>[代码] [代码]<script>[代码][代码]export [代码][代码]default[代码] [代码]{[代码][代码] [代码][代码]components: {},[代码] [代码] [代码][代码]data() {[代码][代码] [代码][代码]return[代码] [代码]{[代码][代码] [代码][代码]pass: [代码][代码]"1234-Hsl"[代码][代码],[代码][代码] [代码][代码]logs: [],[代码][代码] [代码][代码]wifiLists: [][代码][代码] [代码][代码]};[代码][代码] [代码][代码]},[代码][代码] [代码][代码]computed: {[代码][代码] [代码][代码]wifiList() {[代码][代码] [代码][代码]return[代码] [代码]this[代码][代码].wifiLists;[代码][代码] [代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码][代码] [代码][代码]methods: {[代码][代码] [代码][代码] [代码][代码]selecedItem(id) {[代码][代码] [代码][代码]console.log([代码][代码]typeof[代码] [代码]id);[代码][代码] [代码][代码]wx.connectWifi({[代码][代码] [代码][代码]SSID: toString(id),[代码][代码] [代码][代码]password: toString([代码][代码]this[代码][代码].pass),[代码][代码] [代码][代码]success(res) {[代码][代码] [代码][代码]console.log(res);[代码][代码] [代码][代码]},[代码][代码] [代码][代码]complete(complete) {[代码][代码] [代码][代码]console.log([代码][代码]"complete"[代码][代码], complete);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码][代码] [代码][代码]},[代码][代码] [代码][代码]startWifi() {[代码][代码] [代码][代码]wx.startWifi({[代码][代码] [代码][代码]success(res) {[代码][代码] [代码][代码]console.log(res.errMsg);[代码][代码] [代码][代码]},[代码][代码] [代码][代码]complete(complete) {[代码][代码] [代码][代码]console.log([代码][代码]"complete"[代码][代码], complete);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码][代码] [代码][代码]},[代码][代码] [代码][代码]getWifiList() {[代码][代码] [代码][代码]wx.getWifiList({[代码][代码] [代码][代码]success(res) {[代码][代码] [代码][代码]console.log(res);[代码][代码] [代码][代码]},[代码][代码] [代码][代码]complete(complete) {[代码][代码] [代码][代码]console.log([代码][代码]"complete"[代码][代码], complete);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码] [代码] [代码][代码] [代码][代码]},[代码][代码] [代码][代码]startLocalServiceDiscovery() {[代码][代码] [代码][代码]wx.startLocalServiceDiscovery({[代码][代码] [代码][代码]// 当前手机所连的局域网下有一个 _http._tcp. 类型的服务[代码][代码] [代码][代码]serviceType: [代码][代码]"_http._tcp."[代码][代码],[代码][代码] [代码][代码]success: res => {[代码][代码] [代码][代码]console.log([代码][代码]"开始搜索成功"[代码][代码], res);[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: err => {[代码][代码] [代码][代码]console.log([代码][代码]"开始搜索失败"[代码][代码], err);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码][代码] [代码][代码]},[代码][代码] [代码][代码]stopLocalServiceDiscovery() {[代码][代码] [代码][代码]wx.stopLocalServiceDiscovery({[代码][代码] [代码][代码]success: res => {[代码][代码] [代码][代码]console.log([代码][代码]"停止搜索成功"[代码][代码], res);[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: err => {[代码][代码] [代码][代码]console.log([代码][代码]"停止搜索失败"[代码][代码], err);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码][代码] [代码][代码]created() {[代码][代码] [代码][代码]// this.wifi();[代码][代码] [代码][代码]wx.onWifiConnected(wifi => {[代码][代码] [代码][代码]console.log([代码][代码]"wifi"[代码][代码], wifi);[代码][代码] [代码][代码]});[代码][代码] [代码][代码]wx.onGetWifiList(list => {[代码][代码] [代码][代码]this[代码][代码].wifiLists = list.wifiList;[代码][代码] [代码][代码]console.log([代码][代码]"this.wifiListh获取到列表"[代码][代码], [代码][代码]this[代码][代码].wifiLists);[代码][代码] [代码][代码]});[代码][代码] [代码][代码]wx.onLocalServiceResolveFail((serviceType, serviceName) => {[代码][代码] [代码][代码]console.log([代码][代码]"serviceType"[代码][代码], serviceType);[代码][代码] [代码][代码]console.log([代码][代码]"serviceName"[代码][代码], serviceName);[代码][代码] [代码][代码]});[代码][代码] [代码][代码]wx.onLocalServiceFound((serviceType, serviceName, ip, port) => {[代码][代码] [代码][代码]console.log([代码][代码]"serviceType"[代码][代码], serviceType);[代码][代码] [代码][代码]console.log([代码][代码]"serviceName"[代码][代码], serviceName);[代码][代码] [代码][代码]console.log([代码][代码]"ip"[代码][代码], ip);[代码][代码] [代码][代码]console.log([代码][代码]"port"[代码][代码], port);[代码][代码] [代码][代码]});[代码][代码] [代码][代码]}[代码][代码]};[代码][代码]</script>[代码] [代码]<style>[代码][代码].i-input {[代码][代码] [代码][代码]padding: 7px 15px;[代码][代码] [代码][代码]color:[代码] [代码]#495060;[代码][代码]}[代码][代码].item {[代码][代码] [代码][代码]font-size: 16px;[代码][代码] [代码][代码]line-height: 16px;[代码][代码] [代码][代码]text-align: center;[代码][代码] [代码][代码]color: black;[代码][代码] [代码][代码]padding: 5px;[代码][代码]}[代码][代码].log-list {[代码][代码] [代码][代码]display: flex;[代码][代码] [代码][代码]flex-direction: column;[代码][代码] [代码][代码]padding: 40rpx;[代码][代码]}[代码] 提问[代码].log-item {[代码][代码] [代码][代码]margin: 10rpx;[代码][代码]}[代码][代码]</style>[代码]