Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
58a58d67
U
uni-api
项目概览
DCloud
/
uni-api
通知
671
Star
23
Fork
12
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
58a58d67
编写于
12月 03, 2022
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加onWifiConnectedWithPartialInfo
上级
f60e237f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
50 addition
and
8 deletion
+50
-8
pages/index/index.vue
pages/index/index.vue
+4
-0
uni_modules/uni-wifi/package.json
uni_modules/uni-wifi/package.json
+3
-1
uni_modules/uni-wifi/utssdk/app-android/index.uts
uni_modules/uni-wifi/utssdk/app-android/index.uts
+43
-7
未找到文件。
pages/index/index.vue
浏览文件 @
58a58d67
...
...
@@ -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
));
...
...
uni_modules/uni-wifi/package.json
浏览文件 @
58a58d67
...
...
@@ -39,7 +39,9 @@
"getWifiList"
:
"getWifiList"
,
"onGetWifiList"
:
"onGetWifiList"
,
"onWifiConnected"
:
"onWifiConnected"
,
"connectWifi"
:
"connectWifi"
"connectWifi"
:
"connectWifi"
,
"onWifiConnectedWithPartialInfo"
:
"onWifiConnectedWithPartialInfo"
,
"offWifiConnectedWithPartialInfo"
:
"offWifiConnectedWithPartialInfo"
}
},
"dependencies"
:
[],
...
...
uni_modules/uni-wifi/utssdk/app-android/index.uts
浏览文件 @
58a58d67
...
...
@@ -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
}
...
...
@@ -160,7 +159,8 @@ class UniWifiInfo {
this.frequency = connectInfo.getFrequency();
}
}
/**
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录