提交 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,23 +46,25 @@ ...@@ -45,23 +46,25 @@
console.log(res) console.log(res)
}, },
onGetWifiList2_assert0() { onGetWifiList2_assert0() {
const fn = res => console.log('onGetWifiList res', res) console.log(" ------- onGetWifiList2_assert0: ",this.id);
uni.startWifi({success(){ const fn = res => console.log('onGetWifiList res', res)
uni.onGetWifiList(fn) uni.startWifi({success(){
uni.getWifiList({ uni.onGetWifiList(fn)
success() { uni.getWifiList({
console.log('getWifiList success'); success() {
uni.offGetWifiList(fn) console.log('getWifiList success');
uni.stopWifi({ uni.offGetWifiList(fn)
success() {}, uni.stopWifi({
fail(e) { success() {},
console.log("stopWifi fail: ",e); fail(e) {
} console.log("stopWifi fail: ",e);
}) }
} })
}) }
}}) })
}, }})
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
}
} }
} }
...@@ -845,4 +848,5 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) { ...@@ -845,4 +848,5 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) {
} }
option.fail?.(res) option.fail?.(res)
option.complete?.(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.
先完成此消息的编辑!
想要评论请 注册