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

feat: uni-wifi iOS实现startWifi 和stopWifi

上级 862a6d8c
......@@ -50,10 +50,18 @@
partialInfo:false,
complete:(res)=>{
console.log(res);
if (res.errCode == 0) {
uni.showToast({
icon:'none',
title:res.wifi.SSID
})
} else{
uni.showToast({
icon:'none',
title:res.errMsg
})
}
}
});
},
......
......@@ -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,6 +241,22 @@ export function offGetWifiList(callback: UTSCallback) {
* 获取当前连接的wifi信息
*/
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") {
requestLocationPromise((success) => {
if (success == true) {
......@@ -240,7 +264,8 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) {
}else {
let res = {
errCode: 12010,
errMsg: "have no location promise"
errMsg: "have no location promise",
wifi: wifiInfo
}
option.fail?.(res)
option.complete?.(res)
......@@ -249,6 +274,7 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) {
} else{
fetchConnectedWifiWithLocationPromise(option)
}
}
}
/*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册