From eba92949202b20862b4ba7e1fde2e6511c3153ad Mon Sep 17 00:00:00 2001 From: m0_75226990 Date: Wed, 30 Nov 2022 19:47:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20uni-wifi=20iOS=E5=AE=9E=E7=8E=B0startWi?= =?UTF-8?q?fi=20=E5=92=8CstopWifi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.vue | 16 +++-- uni_modules/uni-wifi/utssdk/app-ios/index.uts | 62 +++++++++++++------ 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/pages/index/index.vue b/pages/index/index.vue index c848180..b048071 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 7ec7685..03e0459 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) + } } } -- GitLab