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

修复 getWifilIST 可能多次回调的问题

上级 06350ede
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
memListener:null, memListener:null,
setUserCaptureScreenFlag: false, setUserCaptureScreenFlag: false,
setUserCaptureScreenText: '禁止截屏', setUserCaptureScreenText: '禁止截屏',
permissionGranted: false permissionGranted: false,
id:0
} }
}, },
onLoad() { onLoad() {
...@@ -45,6 +46,7 @@ ...@@ -45,6 +46,7 @@
console.log(res) console.log(res)
}, },
onGetWifiList2_assert0() { onGetWifiList2_assert0() {
console.log(" ------- onGetWifiList2_assert0: ",this.id);
const fn = res => console.log('onGetWifiList res', res) const fn = res => console.log('onGetWifiList res', res)
uni.startWifi({success(){ uni.startWifi({success(){
uni.onGetWifiList(fn) uni.onGetWifiList(fn)
...@@ -61,6 +63,7 @@ ...@@ -61,6 +63,7 @@
} }
}) })
}}) }})
this.id++
}, },
testConnnectWifi(){ testConnnectWifi(){
......
{
"minSdkVersion": "19"
}
\ No newline at end of file
...@@ -306,17 +306,8 @@ class CustomBroadcastReceiver extends BroadcastReceiver { ...@@ -306,17 +306,8 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
if (intent.action == WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) { if (intent.action == WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) {
startWifiScaning = false; startWifiScaning = false;
let ret : UniWifiResult = {
errCode: 0,
errSubject: "uni-getWifiList",
errMsg: "getWifiList:ok"
}
if(Global.supendGetWifiSuccess != null){
Global.supendGetWifiSuccess?.(ret)
}
if(Global.supendGetWifiComplete != null){
Global.supendGetWifiComplete?.(ret)
}
// wifi 扫描结果回调 // wifi 扫描结果回调
let results = this.mWifiManager!.scanResults; let results = this.mWifiManager!.scanResults;
...@@ -336,15 +327,27 @@ class CustomBroadcastReceiver extends BroadcastReceiver { ...@@ -336,15 +327,27 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
const data = new JSONObject(); const data = new JSONObject();
data["wifiList"] = Global.scanList data["wifiList"] = Global.scanList
Global.onGetWifiListCallback?.(data); Global.onGetWifiListCallback?.(data);
/**
* 确保onGetWifiList 只会被执行一次
*/
Global.onGetWifiListCallback = null
} }
// for (let perCallback in Global.onGetWifiListCallback) {
// const data = new JSONObject();
// data["wifiList"] = Global.scanList
// perCallback(data);
// }
} }
let ret : UniWifiResult = {
errCode: 0,
errSubject: "uni-getWifiList",
errMsg: "getWifiList:ok"
}
if(Global.supendGetWifiSuccess != null){
Global.supendGetWifiSuccess?.(ret)
Global.supendGetWifiSuccess = null
}
if(Global.supendGetWifiComplete != null){
Global.supendGetWifiComplete?.(ret)
Global.supendGetWifiComplete = null
}
} }
} }
...@@ -846,3 +849,4 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) { ...@@ -846,3 +849,4 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) {
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.
先完成此消息的编辑!
想要评论请 注册