diff --git a/pages/index/index.vue b/pages/index/index.vue index c8481801dafdf44e1d399b07d8800968861b6426..b048071f0ca1993d089b2af5951ed33bc77134a1 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -50,10 +50,18 @@ partialInfo:false, complete:(res)=>{ console.log(res); - uni.showToast({ - icon:'none', - title:res.wifi.SSID - }) + if (res.errCode == 0) { + uni.showToast({ + icon:'none', + title:res.wifi.SSID + }) + } else{ + uni.showToast({ + icon:'none', + title:res.errMsg + }) + } + } }); }, diff --git a/uni_modules/uni-wifi/utssdk/app-ios/index.uts b/uni_modules/uni-wifi/utssdk/app-ios/index.uts index 7ec768598434c218849549136db5958b30300579..03e0459fbcee87c950b08b6f4b7024f5bb387876 100644 --- a/uni_modules/uni-wifi/utssdk/app-ios/index.uts +++ b/uni_modules/uni-wifi/utssdk/app-ios/index.uts @@ -149,6 +149,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) let bssid = BSSID! as string wifiInfo.SSID = ssid wifiInfo.BSSID = bssid + wifiInfo.secure = false wifiInfo.signalStrength = 0 wifiInfo.frequency = 0 break; @@ -177,7 +178,12 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) - +/* + * 保存全局数据信息 + */ +class GloabInfo { + static alreadyStartWifi: boolean +} /* =================================== 对外暴露的接口 ==============================================*/ @@ -187,11 +193,12 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) * 初始化wifi模块 */ export function startWifi(option: WifiOption) { + GloabInfo.alreadyStartWifi = true let res = { - errCode: 12001, - errMsg: "system not support" + errCode: 0, + errMsg: "startWifi: ok" } - option.fail?.(res) + option.success?.(res) option.complete?.(res) } @@ -199,6 +206,7 @@ export function startWifi(option: WifiOption) { * 停止wifi模块 */ export function stopWifi() { + GloabInfo.alreadyStartWifi = false LocationPromiseService.promiseCompletionHandler = [] } @@ -233,21 +241,39 @@ export function offGetWifiList(callback: UTSCallback) { * 获取当前连接的wifi信息 */ export function getConnectedWifi(option: GetConnectedWifiOptions) { - if (UIDevice.current.systemVersion >= "13.0") { - requestLocationPromise((success) => { - if (success == true) { - fetchConnectedWifiWithLocationPromise(option) - }else { - let res = { - errCode: 12010, - errMsg: "have no location promise" - } - option.fail?.(res) - option.complete?.(res) - } - }) + let wifiInfo = new UniWifiInfo() + wifiInfo.SSID = "" + wifiInfo.BSSID = "" + wifiInfo.secure = false + wifiInfo.signalStrength = 0 + wifiInfo.frequency = 0 + + if (GloabInfo.alreadyStartWifi == false) { + let res = { + errCode: 12000, + errMsg: "not invoke startWifi", + wifi: wifiInfo + } + option.fail?.(res) + option.complete?.(res) } else{ - fetchConnectedWifiWithLocationPromise(option) + if (UIDevice.current.systemVersion >= "13.0") { + requestLocationPromise((success) => { + if (success == true) { + fetchConnectedWifiWithLocationPromise(option) + }else { + let res = { + errCode: 12010, + errMsg: "have no location promise", + wifi: wifiInfo + } + option.fail?.(res) + option.complete?.(res) + } + }) + } else{ + fetchConnectedWifiWithLocationPromise(option) + } } }