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

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

上级 06350ede
......@@ -31,7 +31,8 @@
memListener:null,
setUserCaptureScreenFlag: false,
setUserCaptureScreenText: '禁止截屏',
permissionGranted: false
permissionGranted: false,
id:0
}
},
onLoad() {
......@@ -45,23 +46,25 @@
console.log(res)
},
onGetWifiList2_assert0() {
const fn = res => console.log('onGetWifiList res', res)
uni.startWifi({success(){
uni.onGetWifiList(fn)
uni.getWifiList({
success() {
console.log('getWifiList success');
uni.offGetWifiList(fn)
uni.stopWifi({
success() {},
fail(e) {
console.log("stopWifi fail: ",e);
}
})
}
})
}})
},
console.log(" ------- onGetWifiList2_assert0: ",this.id);
const fn = res => console.log('onGetWifiList res', res)
uni.startWifi({success(){
uni.onGetWifiList(fn)
uni.getWifiList({
success() {
console.log('getWifiList success');
uni.offGetWifiList(fn)
uni.stopWifi({
success() {},
fail(e) {
console.log("stopWifi fail: ",e);
}
})
}
})
}})
this.id++
},
testConnnectWifi(){
......
{
"minSdkVersion": "19"
}
\ No newline at end of file
......@@ -306,17 +306,8 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
if (intent.action == WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) {
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 扫描结果回调
let results = this.mWifiManager!.scanResults;
......@@ -336,15 +327,27 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
const data = new JSONObject();
data["wifiList"] = Global.scanList
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
}
}
}
......@@ -845,4 +848,5 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) {
}
option.fail?.(res)
option.complete?.(res)
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册