提交 58a58d67 编写于 作者: 杜庆泉's avatar 杜庆泉

增加onWifiConnectedWithPartialInfo

上级 f60e237f
......@@ -86,6 +86,10 @@
console.log("onWifiConnected");
console.log(res);
});
uni.onWifiConnectedWithPartialInfo(function(res){
console.log("onWifiConnectedWithPartialInfo");
console.log(res);
});
},fail:(res)=>{
console.log("fail: " + JSON.stringify(res));
......
......@@ -39,7 +39,9 @@
"getWifiList":"getWifiList",
"onGetWifiList":"onGetWifiList",
"onWifiConnected":"onWifiConnected",
"connectWifi":"connectWifi"
"connectWifi":"connectWifi",
"onWifiConnectedWithPartialInfo":"onWifiConnectedWithPartialInfo",
"offWifiConnectedWithPartialInfo":"offWifiConnectedWithPartialInfo"
}
},
"dependencies": [],
......
......@@ -66,6 +66,7 @@ class Global {
static getWifiListCallbackList: UTSCallback[] = []
// wifi链接监听
static onWifiConnectCallbackList: UTSCallback[] = []
static onWifiConnectWithPartialInfoCallbackList: UTSCallback[] = []
}
......@@ -140,8 +141,6 @@ class UniWifiInfo {
* 根据connectInfo 链接信息对wifi数据结构进行初始化
*/
wrapConnectInfo(connectInfo: WifiInfo): void {
console.log(connectInfo.getSSID());
console.log(connectInfo.getBSSID());
if (connectInfo.getBSSID() == null) {
return
}
......@@ -161,6 +160,7 @@ class UniWifiInfo {
}
}
/**
......@@ -230,6 +230,16 @@ function getSecurityType(result:ScanResult):string {
}
function zeroCountNum(source:string):number{
var splitted = source.split(":")
var countNum = 0;
for(perItem in splitted){
if(perItem == "00"){
countNum += 1
}
}
return countNum
}
/**
* 自定义wifi变化广播监听器
*/
......@@ -257,7 +267,8 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
// BroadcastReceiver 中不能执行耗时任务,需要使用setTimeout
// @ts-ignore
let winfo = this.mWifiManager!.getConnectionInfo();
while (winfo.bssid == null) {
while (winfo.bssid == null || zeroCountNum(winfo.bssid) > 4) {
Thread.sleep(1000)
winfo = this.mWifiManager!.getConnectionInfo();
}
......@@ -273,6 +284,13 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
for (let perCallback in Global.onWifiConnectCallbackList) {
perCallback(res);
}
// 封装仅SSID 数据对象
var connectedWithPartialInfo = {
SSID:uniWifiInfo.SSID
}
for (let perCallback in Global.onWifiConnectWithPartialInfoCallbackList) {
perCallback(connectedWithPartialInfo);
}
}, 100);
}
......@@ -377,6 +395,7 @@ export function startWifi(option: WifiOption) {
Global.scanList = []
Global.getWifiListCallbackList = []
Global.onWifiConnectCallbackList = []
Global.onWifiConnectWithPartialInfoCallbackList = []
}
});
......@@ -434,6 +453,12 @@ export function onWifiConnected(callback: UTSCallback) {
Global.onWifiConnectCallbackList.push(callback)
}
export function onWifiConnectedWithPartialInfo(callback: UTSCallback) {
Global.onWifiConnectWithPartialInfoCallbackList.push(callback)
}
/**
* wifi 链接成功的回调取消注册
*/
......@@ -444,6 +469,13 @@ export function offWifiConnected(callback: UTSCallback) {
}
}
export function offWifiConnectedWithPartialInfo(callback: UTSCallback) {
let callbackIndex = Global.onWifiConnectWithPartialInfoCallbackList.indexOf(callback)
if (callbackIndex > 0) {
Global.onWifiConnectWithPartialInfoCallbackList.splice(callbackIndex, 1);
}
}
/**
* 注册Wifi列表的监听事件
*/
......@@ -567,15 +599,19 @@ export function connectWifi(option: WifiConnectOption) {
} catch (e) {
connected = false;
// TODO: handle exception
console.log(e);
// e.printStackTrace();
}
if(!connected){
// 出错了,返回错误
// 兜底的报错
result.errCode = 12010
result.errMsg = "connectWifi:fail:unknown error"
option.fail?.(result)
option.complete?.(result)
return
}
result.errCode = 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册