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

fix: uni-wifi ios调整

上级 41e049a8
...@@ -8,23 +8,23 @@ import { UIDevice } from 'UIKit'; ...@@ -8,23 +8,23 @@ import { UIDevice } from 'UIKit';
* Wifi 函数通用入参封装 * Wifi 函数通用入参封装
*/ */
type WifiOption = { type WifiOption = {
success?: (res: object) => void; success?: (res: UniWifiResult) => void;
fail?: (res: object) => void; fail?: (res: UniWifiResult) => void;
complete?: (res: object) => void; complete?: (res: UniWifiResult) => void;
}; };
/** /**
* Wifi 链接参数封装 * Wifi 链接参数封装
*/ */
type WifiConnectOption = { type WifiConnectOption = {
SSID: string; SSID?: string;
BSSID: string; BSSID?: string;
password: string; password?: string;
maunal: boolean; maunal?: boolean;
partialInfo: boolean; //ios不生效 partialInfo?: boolean; //ios不生效
success?: (res: object) => void; success?: (res: UniWifiResult) => void;
fail?: (res: object) => void; fail?: (res: UniWifiResult) => void;
complete?: (res: object) => void; complete?: (res: UniWifiResult) => void;
} }
/** /**
...@@ -32,9 +32,9 @@ type WifiConnectOption = { ...@@ -32,9 +32,9 @@ type WifiConnectOption = {
*/ */
type GetConnectedWifiOptions = { type GetConnectedWifiOptions = {
partialInfo?: boolean partialInfo?: boolean
success?: (res: UTSJSONObject) => void success?: (res: UniWifiResult) => void
fail?: (res: UTSJSONObject) => void fail?: (res: UniWifiResult) => void
complete?: (res: UTSJSONObject) => void complete?: (res: UniWifiResult) => void
} }
/* /*
...@@ -48,6 +48,15 @@ type UniWifiInfo = { ...@@ -48,6 +48,15 @@ type UniWifiInfo = {
frequency: number; frequency: number;
} }
type UniWifiResult = {
errCode : number,
errSubject : string,
errMsg : string,
wifi: UniWifiInfo | null
}
type UniWifiCallback = () => void
/* /*
* 系统定位权限获取类 * 系统定位权限获取类
...@@ -114,12 +123,13 @@ function requestLocationPromise(@escaping completion: (res: boolean)=>void) { ...@@ -114,12 +123,13 @@ function requestLocationPromise(@escaping completion: (res: boolean)=>void) {
*/ */
function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) { function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) {
let arr = CNCopySupportedInterfaces() let arr = CNCopySupportedInterfaces()
let wifiInfo = new UniWifiInfo() let wifiInfo: UniWifiInfo = {
wifiInfo.BSSID = "" BSSID: "",
wifiInfo.SSID = "" SSID: "",
wifiInfo.secure = false secure: false,
wifiInfo.signalStrength = 0 signalStrength: 0,
wifiInfo.frequency = 0 frequency: 0
}
if (arr != null) { if (arr != null) {
let list = arr! as NSArray let list = arr! as NSArray
...@@ -148,7 +158,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) ...@@ -148,7 +158,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
} }
if (wifiInfo.BSSID.length > 0 && wifiInfo.SSID.length > 0) { if (wifiInfo.BSSID.length > 0 && wifiInfo.SSID.length > 0) {
let res = { let res: UniWifiResult = {
errSubject: "uni-getConnectedWifi", errSubject: "uni-getConnectedWifi",
errCode: 0, errCode: 0,
errMsg: "getConnectedWifi:ok", errMsg: "getConnectedWifi:ok",
...@@ -157,19 +167,21 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) ...@@ -157,19 +167,21 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
option.success?.(res) option.success?.(res)
option.complete?.(res) option.complete?.(res)
}else { }else {
const res = { const res: UniWifiResult = {
errSubject: "uni-getConnectedWifi", errSubject: "uni-getConnectedWifi",
errCode: 12010, errCode: 12010,
errMsg: "getConnectedWifi:system internal error" errMsg: "getConnectedWifi:system internal error",
wifi: null
} }
option.fail?.(res) option.fail?.(res)
option.complete?.(res) option.complete?.(res)
} }
}else { }else {
const res = { const res: UniWifiResult = {
errSubject: "uni-getConnectedWifi", errSubject: "uni-getConnectedWifi",
errCode: 12010, errCode: 12010,
errMsg: "getConnectedWifi:system internal error" errMsg: "getConnectedWifi:system internal error",
wifi: null
} }
option.fail?.(res) option.fail?.(res)
option.complete?.(res) option.complete?.(res)
...@@ -182,7 +194,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) ...@@ -182,7 +194,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
* 保存全局数据信息 * 保存全局数据信息
*/ */
class UniWiFiModuleGloabInfo { class UniWiFiModuleGloabInfo {
static alreadyStartWifi: boolean static alreadyStartWifi: boolean = false
} }
/* =================================== 对外暴露的接口 ==============================================*/ /* =================================== 对外暴露的接口 ==============================================*/
...@@ -194,10 +206,11 @@ class UniWiFiModuleGloabInfo { ...@@ -194,10 +206,11 @@ class UniWiFiModuleGloabInfo {
*/ */
export function startWifi(option: WifiOption) { export function startWifi(option: WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = true UniWiFiModuleGloabInfo.alreadyStartWifi = true
let res = { let res: UniWifiResult = {
errSubject: "uni-startWifi", errSubject: "uni-startWifi",
errCode: 0, errCode: 0,
errMsg: "startWifi:ok" errMsg: "startWifi:ok",
wifi: null
} }
option.success?.(res) option.success?.(res)
option.complete?.(res) option.complete?.(res)
...@@ -209,10 +222,11 @@ export function startWifi(option: WifiOption) { ...@@ -209,10 +222,11 @@ export function startWifi(option: WifiOption) {
export function stopWifi(option: WifiOption) { export function stopWifi(option: WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = false UniWiFiModuleGloabInfo.alreadyStartWifi = false
LocationPromiseService.promiseCompletionHandler = [] LocationPromiseService.promiseCompletionHandler = []
let res = { let res: UniWifiResult = {
errSubject: "uni-stopWifi", errSubject: "uni-stopWifi",
errCode: 0, errCode: 0,
errMsg: "stopWifi:ok" errMsg: "stopWifi:ok",
wifi: null
} }
option.success?.(res) option.success?.(res)
option.complete?.(res) option.complete?.(res)
...@@ -222,10 +236,11 @@ export function stopWifi(option: WifiOption) { ...@@ -222,10 +236,11 @@ export function stopWifi(option: WifiOption) {
* 获取wifi列表, 在调用之前需要引导用户跳转到系统设置-WIFI设置页面,系统搜索周边wifi后app才能接收到回调 * 获取wifi列表, 在调用之前需要引导用户跳转到系统设置-WIFI设置页面,系统搜索周边wifi后app才能接收到回调
*/ */
export function getWifiList(option: WifiOption) { export function getWifiList(option: WifiOption) {
let res = { let res: UniWifiResult = {
errSubject: "uni-getWifiList", errSubject: "uni-getWifiList",
errCode: 12001, errCode: 12001,
errMsg: "getWifiList:system not support" errMsg: "getWifiList:system not support",
wifi: null
} }
option.fail?.(res) option.fail?.(res)
option.complete?.(res) option.complete?.(res)
...@@ -234,14 +249,14 @@ export function getWifiList(option: WifiOption) { ...@@ -234,14 +249,14 @@ export function getWifiList(option: WifiOption) {
/* 获取wifi列表的回调 /* 获取wifi列表的回调
* note: 请在getWifiList方法的回调里调用该方法 * note: 请在getWifiList方法的回调里调用该方法
*/ */
export function onGetWifiList(callback: UTSCallback) { export function onGetWifiList(callback: UniWifiCallback) {
} }
/* /*
* 注销获取wifi列表的回调 * 注销获取wifi列表的回调
*/ */
export function offGetWifiList(callback: UTSCallback) { export function offGetWifiList(callback: UniWifiCallback) {
} }
...@@ -251,10 +266,11 @@ export function offGetWifiList(callback: UTSCallback) { ...@@ -251,10 +266,11 @@ export function offGetWifiList(callback: UTSCallback) {
*/ */
export function getConnectedWifi(option: GetConnectedWifiOptions) { export function getConnectedWifi(option: GetConnectedWifiOptions) {
if (UniWiFiModuleGloabInfo.alreadyStartWifi == false) { if (UniWiFiModuleGloabInfo.alreadyStartWifi == false) {
let res = { let res: UniWifiResult = {
errSubject: "uni-getConnectedWifi", errSubject: "uni-getConnectedWifi",
errCode: 12000, errCode: 12000,
errMsg: "getConnectedWifi:not init", errMsg: "getConnectedWifi:not init",
wifi: null
} }
option.fail?.(res) option.fail?.(res)
option.complete?.(res) option.complete?.(res)
...@@ -264,10 +280,11 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) { ...@@ -264,10 +280,11 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) {
if (success == true) { if (success == true) {
fetchConnectedWifiWithLocationPromise(option) fetchConnectedWifiWithLocationPromise(option)
}else { }else {
let res = { let res: UniWifiResult = {
errSubject: "uni-getConnectedWifi", errSubject: "uni-getConnectedWifi",
errCode: 12007, errCode: 12007,
errMsg: "getConnectedWifi:user denied", errMsg: "getConnectedWifi:user denied",
wifi: null
} }
option.fail?.(res) option.fail?.(res)
option.complete?.(res) option.complete?.(res)
...@@ -283,10 +300,11 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) { ...@@ -283,10 +300,11 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) {
* 连接wifi * 连接wifi
*/ */
export function connectWifi(option: WifiConnectOption) { export function connectWifi(option: WifiConnectOption) {
let res = { let res: UniWifiResult = {
errSubject: "uni-connectWifi", errSubject: "uni-connectWifi",
errCode: 12001, errCode: 12001,
errMsg: "connectWifi:system not support" errMsg: "connectWifi:system not support",
wifi: null
} }
option.fail?.(res) option.fail?.(res)
option.complete?.(res) option.complete?.(res)
...@@ -296,28 +314,28 @@ export function connectWifi(option: WifiConnectOption) { ...@@ -296,28 +314,28 @@ export function connectWifi(option: WifiConnectOption) {
/* /*
* 连上wifi事件的监听函数 * 连上wifi事件的监听函数
*/ */
export function onWifiConnected(callback: UTSCallback) { export function onWifiConnected(callback: UniWifiCallback) {
} }
/* /*
* 连上wifi事件的监听函数, wifiInfo仅包含ssid * 连上wifi事件的监听函数, wifiInfo仅包含ssid
*/ */
export function onWifiConnectedWithPartialInfo(callback: UTSCallback) { export function onWifiConnectedWithPartialInfo(callback: UniWifiCallback) {
} }
/* /*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。 * 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/ */
export function offWifiConnected(callback: UTSCallback | null) { export function offWifiConnected(callback: UniWifiCallback | null) {
} }
/* /*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。 * 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/ */
export function onOffWifiConnectedWithPartialInfo(callback: UTSCallback | null) { export function onOffWifiConnectedWithPartialInfo(callback: UniWifiCallback | null) {
} }
...@@ -325,10 +343,11 @@ export function onOffWifiConnectedWithPartialInfo(callback: UTSCallback | null) ...@@ -325,10 +343,11 @@ export function onOffWifiConnectedWithPartialInfo(callback: UTSCallback | null)
* 设置 wifiList 中 AP 的相关信息。在 onGetWifiList 回调后调用,iOS特有接口。 * 设置 wifiList 中 AP 的相关信息。在 onGetWifiList 回调后调用,iOS特有接口。
*/ */
export function setWifiList(option: WifiOption) { export function setWifiList(option: WifiOption) {
let res = { let res: UniWifiResult = {
errSubject: "uni-setWifiList", errSubject: "uni-setWifiList",
errCode: 12001, errCode: 12001,
errMsg: "setWifiList:system not support" errMsg: "setWifiList:system not support",
wifi: null
} }
option.fail?.(res) option.fail?.(res)
option.complete?.(res) option.complete?.(res)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册