提交 eba92949 编写于 作者: lizhongyi_'s avatar lizhongyi_

feat: uni-wifi iOS实现startWifi 和stopWifi

上级 862a6d8c
...@@ -50,10 +50,18 @@ ...@@ -50,10 +50,18 @@
partialInfo:false, partialInfo:false,
complete:(res)=>{ complete:(res)=>{
console.log(res); console.log(res);
if (res.errCode == 0) {
uni.showToast({ uni.showToast({
icon:'none', icon:'none',
title:res.wifi.SSID title:res.wifi.SSID
}) })
} else{
uni.showToast({
icon:'none',
title:res.errMsg
})
}
} }
}); });
}, },
......
...@@ -149,6 +149,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) ...@@ -149,6 +149,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
let bssid = BSSID! as string let bssid = BSSID! as string
wifiInfo.SSID = ssid wifiInfo.SSID = ssid
wifiInfo.BSSID = bssid wifiInfo.BSSID = bssid
wifiInfo.secure = false
wifiInfo.signalStrength = 0 wifiInfo.signalStrength = 0
wifiInfo.frequency = 0 wifiInfo.frequency = 0
break; break;
...@@ -177,7 +178,12 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) ...@@ -177,7 +178,12 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
/*
* 保存全局数据信息
*/
class GloabInfo {
static alreadyStartWifi: boolean
}
/* =================================== 对外暴露的接口 ==============================================*/ /* =================================== 对外暴露的接口 ==============================================*/
...@@ -187,11 +193,12 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) ...@@ -187,11 +193,12 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
* 初始化wifi模块 * 初始化wifi模块
*/ */
export function startWifi(option: WifiOption) { export function startWifi(option: WifiOption) {
GloabInfo.alreadyStartWifi = true
let res = { let res = {
errCode: 12001, errCode: 0,
errMsg: "system not support" errMsg: "startWifi: ok"
} }
option.fail?.(res) option.success?.(res)
option.complete?.(res) option.complete?.(res)
} }
...@@ -199,6 +206,7 @@ export function startWifi(option: WifiOption) { ...@@ -199,6 +206,7 @@ export function startWifi(option: WifiOption) {
* 停止wifi模块 * 停止wifi模块
*/ */
export function stopWifi() { export function stopWifi() {
GloabInfo.alreadyStartWifi = false
LocationPromiseService.promiseCompletionHandler = [] LocationPromiseService.promiseCompletionHandler = []
} }
...@@ -233,6 +241,22 @@ export function offGetWifiList(callback: UTSCallback) { ...@@ -233,6 +241,22 @@ export function offGetWifiList(callback: UTSCallback) {
* 获取当前连接的wifi信息 * 获取当前连接的wifi信息
*/ */
export function getConnectedWifi(option: GetConnectedWifiOptions) { export function getConnectedWifi(option: GetConnectedWifiOptions) {
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{
if (UIDevice.current.systemVersion >= "13.0") { if (UIDevice.current.systemVersion >= "13.0") {
requestLocationPromise((success) => { requestLocationPromise((success) => {
if (success == true) { if (success == true) {
...@@ -240,7 +264,8 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) { ...@@ -240,7 +264,8 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) {
}else { }else {
let res = { let res = {
errCode: 12010, errCode: 12010,
errMsg: "have no location promise" errMsg: "have no location promise",
wifi: wifiInfo
} }
option.fail?.(res) option.fail?.(res)
option.complete?.(res) option.complete?.(res)
...@@ -249,6 +274,7 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) { ...@@ -249,6 +274,7 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) {
} else{ } else{
fetchConnectedWifiWithLocationPromise(option) fetchConnectedWifiWithLocationPromise(option)
} }
}
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册