Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
a5a2d8fd
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看板
提交
a5a2d8fd
编写于
3月 15, 2023
作者:
lizhongyi_
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
uni-wifi新增interface
上级
bbec54cb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
143 addition
and
82 deletion
+143
-82
uni_modules/uni-wifi/utssdk/app-ios/index.uts
uni_modules/uni-wifi/utssdk/app-ios/index.uts
+52
-82
uni_modules/uni-wifi/utssdk/interface.uts
uni_modules/uni-wifi/utssdk/interface.uts
+91
-0
未找到文件。
uni_modules/uni-wifi/utssdk/app-ios/index.uts
浏览文件 @
a5a2d8fd
...
@@ -3,50 +3,8 @@ import { CaptiveNetwork, kCNNetworkInfoKeySSID, kCNNetworkInfoKeyBSSID } from 'S
...
@@ -3,50 +3,8 @@ import { CaptiveNetwork, kCNNetworkInfoKeySSID, kCNNetworkInfoKeyBSSID } from 'S
import { NSArray, NSDictionary } from 'Foundation';
import { NSArray, NSDictionary } from 'Foundation';
import { CFString } from 'CoreFoundation';
import { CFString } from 'CoreFoundation';
import { UIDevice } from 'UIKit';
import { UIDevice } from 'UIKit';
import { UniWifiResult, GetConnectedWifiOptions, WifiConnectOption, WifiOption, UniWifiInfo, UniWifiCallback, StartWifi, StopWifi, GetWifiList, GetConnectedWifi, OnGetWifiList, OnWifiConnectedWithPartialInfo, OnOffWifiConnectedWithPartialInfo, OnWifiConnected, ConnectWifi, OffGetWifiList, OffWifiConnected, SetWifiList } from "../interface.uts"
/**
* Wifi 函数通用入参封装
*/
type WifiOption = {
success?: (res: object) => void;
fail?: (res: object) => void;
complete?: (res: object) => void;
};
/**
* Wifi 链接参数封装
*/
type WifiConnectOption = {
SSID: string;
BSSID: string;
password: string;
maunal: boolean;
partialInfo: boolean; //ios不生效
success?: (res: object) => void;
fail?: (res: object) => void;
complete?: (res: object) => void;
}
/**
* 获取当前链接的wifi信息
*/
type GetConnectedWifiOptions = {
partialInfo?: boolean
success?: (res: UTSJSONObject) => void
fail?: (res: UTSJSONObject) => void
complete?: (res: UTSJSONObject) => void
}
/*
* 对外暴露的wifi信息
*/
type UniWifiInfo = {
SSID: string;
BSSID: string;
secure: boolean;
signalStrength: number;
frequency: number;
}
/*
/*
...
@@ -114,12 +72,13 @@ function requestLocationPromise(@escaping completion: (res: boolean)=>void) {
...
@@ -114,12 +72,13 @@ function requestLocationPromise(@escaping completion: (res: boolean)=>void) {
*/
*/
function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) {
function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) {
let arr = CNCopySupportedInterfaces()
let arr = CNCopySupportedInterfaces()
let wifiInfo = new UniWifiInfo()
let wifiInfo: UniWifiInfo = {
wifiInfo.BSSID = ""
BSSID: "",
wifiInfo.SSID = ""
SSID: "",
wifiInfo.secure = false
secure: false,
wifiInfo.signalStrength = 0
signalStrength: 0,
wifiInfo.frequency = 0
frequency: 0
}
if (arr != null) {
if (arr != null) {
let list = arr! as NSArray
let list = arr! as NSArray
...
@@ -148,7 +107,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
...
@@ -148,7 +107,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
}
}
if (wifiInfo.BSSID.length > 0 && wifiInfo.SSID.length > 0) {
if (wifiInfo.BSSID.length > 0 && wifiInfo.SSID.length > 0) {
let res = {
let res
: UniWifiResult
= {
errSubject: "uni-getConnectedWifi",
errSubject: "uni-getConnectedWifi",
errCode: 0,
errCode: 0,
errMsg: "getConnectedWifi:ok",
errMsg: "getConnectedWifi:ok",
...
@@ -157,19 +116,21 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
...
@@ -157,19 +116,21 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
option.success?.(res)
option.success?.(res)
option.complete?.(res)
option.complete?.(res)
}else {
}else {
const res = {
const res
: UniWifiResult
= {
errSubject: "uni-getConnectedWifi",
errSubject: "uni-getConnectedWifi",
errCode: 12010,
errCode: 12010,
errMsg: "getConnectedWifi:system internal error"
errMsg: "getConnectedWifi:system internal error",
wifi: null
}
}
option.fail?.(res)
option.fail?.(res)
option.complete?.(res)
option.complete?.(res)
}
}
}else {
}else {
const res = {
const res
: UniWifiResult
= {
errSubject: "uni-getConnectedWifi",
errSubject: "uni-getConnectedWifi",
errCode: 12010,
errCode: 12010,
errMsg: "getConnectedWifi:system internal error"
errMsg: "getConnectedWifi:system internal error",
wifi: null
}
}
option.fail?.(res)
option.fail?.(res)
option.complete?.(res)
option.complete?.(res)
...
@@ -182,7 +143,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
...
@@ -182,7 +143,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
* 保存全局数据信息
* 保存全局数据信息
*/
*/
class UniWiFiModuleGloabInfo {
class UniWiFiModuleGloabInfo {
static alreadyStartWifi: boolean
static alreadyStartWifi: boolean
= false
}
}
/* =================================== 对外暴露的接口 ==============================================*/
/* =================================== 对外暴露的接口 ==============================================*/
...
@@ -192,12 +153,14 @@ class UniWiFiModuleGloabInfo {
...
@@ -192,12 +153,14 @@ class UniWiFiModuleGloabInfo {
/*
/*
* 初始化wifi模块
* 初始化wifi模块
*/
*/
export function startWifi(option: WifiOption) {
export const startWifi : StartWifi = function (option : WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = true
UniWiFiModuleGloabInfo.alreadyStartWifi = true
let res = {
let res
: UniWifiResult
= {
errSubject: "uni-startWifi",
errSubject: "uni-startWifi",
errCode: 0,
errCode: 0,
errMsg: "startWifi:ok"
errMsg: "startWifi:ok",
wifi: null
}
}
option.success?.(res)
option.success?.(res)
option.complete?.(res)
option.complete?.(res)
...
@@ -206,13 +169,14 @@ export function startWifi(option: WifiOption) {
...
@@ -206,13 +169,14 @@ export function startWifi(option: WifiOption) {
/*
/*
* 停止wifi模块
* 停止wifi模块
*/
*/
export
function stopWifi(option
: WifiOption) {
export
const stopWifi : StopWifi = function (option
: WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = false
UniWiFiModuleGloabInfo.alreadyStartWifi = false
LocationPromiseService.promiseCompletionHandler = []
LocationPromiseService.promiseCompletionHandler = []
let res = {
let res
: UniWifiResult
= {
errSubject: "uni-stopWifi",
errSubject: "uni-stopWifi",
errCode: 0,
errCode: 0,
errMsg: "stopWifi:ok"
errMsg: "stopWifi:ok",
wifi: null
}
}
option.success?.(res)
option.success?.(res)
option.complete?.(res)
option.complete?.(res)
...
@@ -221,11 +185,12 @@ export function stopWifi(option: WifiOption) {
...
@@ -221,11 +185,12 @@ export function stopWifi(option: WifiOption) {
/*
/*
* 获取wifi列表, 在调用之前需要引导用户跳转到系统设置-WIFI设置页面,系统搜索周边wifi后app才能接收到回调
* 获取wifi列表, 在调用之前需要引导用户跳转到系统设置-WIFI设置页面,系统搜索周边wifi后app才能接收到回调
*/
*/
export
function getWifiList(option
: WifiOption) {
export
const getWifiList : GetWifiList = function (option
: WifiOption) {
let res = {
let res
: UniWifiResult
= {
errSubject: "uni-getWifiList",
errSubject: "uni-getWifiList",
errCode: 12001,
errCode: 12001,
errMsg: "getWifiList:system not support"
errMsg: "getWifiList:system not support",
wifi: null
}
}
option.fail?.(res)
option.fail?.(res)
option.complete?.(res)
option.complete?.(res)
...
@@ -234,27 +199,28 @@ export function getWifiList(option: WifiOption) {
...
@@ -234,27 +199,28 @@ export function getWifiList(option: WifiOption) {
/* 获取wifi列表的回调
/* 获取wifi列表的回调
* note: 请在getWifiList方法的回调里调用该方法
* note: 请在getWifiList方法的回调里调用该方法
*/
*/
export
function onGetWifiList(callback: UTS
Callback) {
export
const onGetWifiList : OnGetWifiList = function (callback: UniWifi
Callback) {
}
}
/*
/*
* 注销获取wifi列表的回调
* 注销获取wifi列表的回调
*/
*/
export
function offGetWifiList(callback: UTS
Callback) {
export
const offGetWifiList : OffGetWifiList = function (callback: UniWifi
Callback) {
}
}
/*
/*
* 获取当前连接的wifi信息
* 获取当前连接的wifi信息
*/
*/
export
function getConnectedWifi
(option: GetConnectedWifiOptions) {
export
const getConnectedWifi : GetConnectedWifi = function
(option: GetConnectedWifiOptions) {
if (UniWiFiModuleGloabInfo.alreadyStartWifi == false) {
if (UniWiFiModuleGloabInfo.alreadyStartWifi == false) {
let res = {
let res
: UniWifiResult
= {
errSubject: "uni-getConnectedWifi",
errSubject: "uni-getConnectedWifi",
errCode: 12000,
errCode: 12000,
errMsg: "getConnectedWifi:not init",
errMsg: "getConnectedWifi:not init",
wifi: null
}
}
option.fail?.(res)
option.fail?.(res)
option.complete?.(res)
option.complete?.(res)
...
@@ -264,10 +230,11 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) {
...
@@ -264,10 +230,11 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) {
if (success == true) {
if (success == true) {
fetchConnectedWifiWithLocationPromise(option)
fetchConnectedWifiWithLocationPromise(option)
}else {
}else {
let res = {
let res
: UniWifiResult
= {
errSubject: "uni-getConnectedWifi",
errSubject: "uni-getConnectedWifi",
errCode: 12007,
errCode: 12007,
errMsg: "getConnectedWifi:user denied",
errMsg: "getConnectedWifi:user denied",
wifi: null
}
}
option.fail?.(res)
option.fail?.(res)
option.complete?.(res)
option.complete?.(res)
...
@@ -282,11 +249,12 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) {
...
@@ -282,11 +249,12 @@ export function getConnectedWifi(option: GetConnectedWifiOptions) {
/*
/*
* 连接wifi
* 连接wifi
*/
*/
export
function connectWifi
(option: WifiConnectOption) {
export
const connectWifi : ConnectWifi = function
(option: WifiConnectOption) {
let res = {
let res
: UniWifiResult
= {
errSubject: "uni-connectWifi",
errSubject: "uni-connectWifi",
errCode: 12001,
errCode: 12001,
errMsg: "connectWifi:system not support"
errMsg: "connectWifi:system not support",
wifi: null
}
}
option.fail?.(res)
option.fail?.(res)
option.complete?.(res)
option.complete?.(res)
...
@@ -296,39 +264,41 @@ export function connectWifi(option: WifiConnectOption) {
...
@@ -296,39 +264,41 @@ export function connectWifi(option: WifiConnectOption) {
/*
/*
* 连上wifi事件的监听函数
* 连上wifi事件的监听函数
*/
*/
export
function onWifiConnected(callback: UTS
Callback) {
export
const onWifiConnected : OnWifiConnected = function (callback: UniWifi
Callback) {
}
}
/*
/*
* 连上wifi事件的监听函数, wifiInfo仅包含ssid
* 连上wifi事件的监听函数, wifiInfo仅包含ssid
*/
*/
export
function onWifiConnectedWithPartialInfo(callback: UTS
Callback) {
export
const onWifiConnectedWithPartialInfo : OnWifiConnectedWithPartialInfo = function (callback: UniWifi
Callback) {
}
}
/*
/*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/
*/
export
function offWifiConnected(callback: UTS
Callback | null) {
export
const offWifiConnected : OffWifiConnected = function (callback: UniWifi
Callback | null) {
}
}
/*
/*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/
*/
export
function onOffWifiConnectedWithPartialInfo(callback: UTS
Callback | null) {
export
const onOffWifiConnectedWithPartialInfo : OnOffWifiConnectedWithPartialInfo = function (callback: UniWifi
Callback | null) {
}
}
/*
/*
* 设置 wifiList 中 AP 的相关信息。在 onGetWifiList 回调后调用,iOS特有接口。
* 设置 wifiList 中 AP 的相关信息。在 onGetWifiList 回调后调用,iOS特有接口。
*/
*/
export
function setWifiList
(option: WifiOption) {
export
const setWifiList : SetWifiList = function
(option: WifiOption) {
let res = {
let res
: UniWifiResult
= {
errSubject: "uni-setWifiList",
errSubject: "uni-setWifiList",
errCode: 12001,
errCode: 12001,
errMsg: "setWifiList:system not support"
errMsg: "setWifiList:system not support",
wifi: null
}
}
option.fail?.(res)
option.fail?.(res)
option.complete?.(res)
option.complete?.(res)
...
...
uni_modules/uni-wifi/utssdk/interface.uts
0 → 100644
浏览文件 @
a5a2d8fd
/**
* Wifi 函数通用入参封装
*/
export type WifiOption = {
success?: (res: UniWifiResult) => void;
fail?: (res: UniWifiResult) => void;
complete?: (res: UniWifiResult) => void;
};
/**
* Wifi 链接参数封装
*/
export type WifiConnectOption = {
SSID: string;
BSSID: string;
password: string;
maunal: boolean;
partialInfo: boolean; //ios不生效
success?: (res: UniWifiResult) => void;
fail?: (res: UniWifiResult) => void;
complete?: (res: UniWifiResult) => void;
}
/**
* 获取当前链接的wifi信息
*/
export type GetConnectedWifiOptions = {
partialInfo?: boolean
success?: (res: UniWifiResult) => void
fail?: (res: UniWifiResult) => void
complete?: (res: UniWifiResult) => void
}
/*
* 对外暴露的wifi信息
*/
export type UniWifiInfo = {
SSID: string;
BSSID: string;
secure: boolean;
signalStrength: number;
frequency: number;
}
export type UniWifiResult = {
errCode : number,
errSubject : string,
errMsg : string,
wifi: UniWifiInfo | null
}
export type UniWifiCallback = () => void
export type StartWifi = (option: WifiOption) => void
export type StopWifi = (option: WifiOption) => void
export type GetWifiList = (option: WifiOption) => void
export type OnGetWifiList = (callback: UniWifiCallback) => void
export type OffGetWifiList = (callback: UniWifiCallback) => void
export type GetConnectedWifi = (option: GetConnectedWifiOptions) => void
export type ConnectWifi = (option: WifiConnectOption) => void
export type OnWifiConnected = (callback: UniWifiCallback) => void
export type OnWifiConnectedWithPartialInfo = (callback: UniWifiCallback) => void
export type OffWifiConnected = (callback: UniWifiCallback | null) => void
export type OnOffWifiConnectedWithPartialInfo = (callback: UniWifiCallback | null) => void
export type SetWifiList = (option: WifiOption) => void
interface uni {
startWifi : StartWifi,
stopWifi : StopWifi,
getWifiList : GetWifiList,
onGetWifiList : OnGetWifiList,
offGetWifiList : OffGetWifiList,
getConnectedWifi : GetConnectedWifi,
onWifiConnected : OnWifiConnected,
onWifiConnectedWithPartialInfo : OnWifiConnectedWithPartialInfo,
offWifiConnected : OffWifiConnected,
onOffWifiConnectedWithPartialInfo : OnOffWifiConnectedWithPartialInfo,
setWifiList : SetWifiList,
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录