Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
6afd901e
U
uni-api
项目概览
DCloud
/
uni-api
通知
704
Star
23
Fork
14
代码
文件
提交
分支
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看板
提交
6afd901e
编写于
11月 10, 2023
作者:
lizhongyi_
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
uni-wifi iOS调整
上级
bfe5f46d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
81 addition
and
69 deletion
+81
-69
uni_modules/uni-wifi/utssdk/app-ios/index.uts
uni_modules/uni-wifi/utssdk/app-ios/index.uts
+53
-52
uni_modules/uni-wifi/utssdk/index.d.ts
uni_modules/uni-wifi/utssdk/index.d.ts
+25
-14
uni_modules/uni-wifi/utssdk/interface.uts
uni_modules/uni-wifi/utssdk/interface.uts
+3
-3
未找到文件。
uni_modules/uni-wifi/utssdk/app-ios/index.uts
浏览文件 @
6afd901e
...
...
@@ -3,20 +3,21 @@ import { CaptiveNetwork, kCNNetworkInfoKeySSID, kCNNetworkInfoKeyBSSID } from 'S
import { NSArray, NSDictionary } from 'Foundation';
import { CFString } from 'CoreFoundation';
import { UIDevice } from 'UIKit';
import { WifiOption, WifiConnectOption, GetConnectedWifiOptions, UniWifiInfo, UniWifiResult, UniWifiCallback, StartWifi, StopWifi, GetWifiList, OnGetWifiList, OffGetWifiList, GetConnectedWifi, ConnectWifi, OnWifiConnected, OnWifiConnectedWithPartialInfo, OffWifiConnected, OnOffWifiConnectedWithPartialInfo, SetWifiList } from "../interface.uts"
import { UniWifiResultCallbackWithPartialInfo, UniGetWifiListCallback, UniWifiResultCallback, WifiOption, WifiConnectOption, GetConnectedWifiOptions, UniWifiInfo, UniWifiResult, UniWifiCallback, StartWifi, StopWifi, GetWifiList, OnGetWifiList, OffGetWifiList, GetConnectedWifi, ConnectWifi, OnWifiConnected, OnWifiConnectedWithPartialInfo, OffWifiConnected, OffWifiConnectedWithPartialInfo, SetWifiList } from "../interface.uts"
import { WifiFailImpl, getErrcode } from '../unierror';
/*
/*
* 系统定位权限获取类
*/
class LocationPromiseService implements CLLocationManagerDelegate {
static promiseCompletionHandler: ((res: boolean)=>void)[] = []
manager?: CLLocationManager
constructor(manager?: CLLocationManager) {
this.manager = manager
}
initlizeManager(): boolean {
if (this.manager == null) {
this.manager = new CLLocationManager()
...
...
@@ -24,20 +25,20 @@ class LocationPromiseService implements CLLocationManagerDelegate {
}
return true
}
locationManager(manager: CLLocationManager, @argumentLabel("didChangeAuthorization") status: CLAuthorizationStatus) {
if (status == CLAuthorizationStatus.authorizedAlways || status == CLAuthorizationStatus.authorizedWhenInUse) {
LocationPromiseService.promiseCompletionHandler.forEach((handler): void => {
handler(true)
})
} else if (status == CLAuthorizationStatus.notDetermined) {
} else if (status == CLAuthorizationStatus.notDetermined) {
manager.requestWhenInUseAuthorization()
} else if (status == CLAuthorizationStatus.denied) {
LocationPromiseService.promiseCompletionHandler.forEach((handler): void => {
handler(false)
})
}
}
}
requestPromise(@escaping completion: (res: boolean)=>void) {
let status: CLAuthorizationStatus = CLLocationManager.authorizationStatus()
if (status == CLAuthorizationStatus.notDetermined) {
...
...
@@ -52,20 +53,20 @@ class LocationPromiseService implements CLLocationManagerDelegate {
this.manager!.requestWhenInUseAuthorization()
LocationPromiseService.promiseCompletionHandler.push(completion)
}
}
}
}
}
const locationPromiseService: LocationPromiseService = new LocationPromiseService(null)
/*
* 获取系统定位权限
/*
* 获取系统定位权限
*/
function requestLocationPromise(@escaping completion: (res: boolean)=>void) {
locationPromiseService.requestPromise(completion)
}
/*
/*
* 获取当前连接的wifi信息(通过定位权限)
*/
function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) {
...
...
@@ -76,20 +77,20 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
secure: false,
signalStrength: 0,
frequency: 0
}
}
if (arr != null) {
let list = arr! as NSArray
let index: Int = 0
while (index < list.count) {
let item = list[index]
while (index < list.count) {
let item = list[index]
let interfaceName = item as string
let dic = CNCopyCurrentNetworkInfo(interfaceName as CFString)
if (dic != null) {
let dict = dic! as NSDictionary
let SSID = dict[kCNNetworkInfoKeySSID as string]
let SSID = dict[kCNNetworkInfoKeySSID as string]
let BSSID = dict[kCNNetworkInfoKeyBSSID as string]
if (SSID != null && BSSID != null) {
let ssid = SSID! as string
let bssid = BSSID! as string
...
...
@@ -103,7 +104,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
}
index++
}
if (wifiInfo.BSSID!.length > 0 && wifiInfo.SSID.length > 0) {
let res: UniWifiResult = {
errSubject: "uni-getConnectedWifi",
...
...
@@ -114,12 +115,12 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
option.success?.(res)
option.complete?.(res)
}else {
let err = new UniError("uni-getConnectedWifi",12010,"getConnectedWifi:system internal error"
);
let err = new WifiFailImpl(getErrcode(12010)
);
option.fail?.(err)
option.complete?.(err)
}
}else {
let err = new UniError("uni-getConnectedWifi",12010,"getConnectedWifi:system internal error"
);
let err = new WifiFailImpl(getErrcode(12010)
);
option.fail?.(err)
option.complete?.(err)
}
...
...
@@ -127,7 +128,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
/*
/*
* 保存全局数据信息
*/
class UniWiFiModuleGloabInfo {
...
...
@@ -138,14 +139,14 @@ class UniWiFiModuleGloabInfo {
/*
* 初始化wifi模块
/*
* 初始化wifi模块
*/
export const startWifi: StartWifi = function (option: WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = true
let res: UniWifiResult = {
errSubject: "uni-startWifi",
errCode: 0,
errCode: 0,
errMsg: "startWifi:ok",
wifi: null
}
...
...
@@ -153,15 +154,15 @@ export const startWifi: StartWifi = function (option: WifiOption) {
option.complete?.(res)
}
/*
* 停止wifi模块
/*
* 停止wifi模块
*/
export const stopWifi: StopWifi = function (option: WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = false
LocationPromiseService.promiseCompletionHandler = []
LocationPromiseService.promiseCompletionHandler = []
let res: UniWifiResult = {
errSubject: "uni-stopWifi",
errCode: 0,
errCode: 0,
errMsg: "stopWifi:ok",
wifi: null
}
...
...
@@ -169,11 +170,11 @@ export const stopWifi: StopWifi = function (option: WifiOption) {
option.complete?.(res)
}
/*
/*
* 获取wifi列表, 在调用之前需要引导用户跳转到系统设置-WIFI设置页面,系统搜索周边wifi后app才能接收到回调
*/
export const getWifiList: GetWifiList = function (option: WifiOption) {
let err = new UniError("uni-getWifiList",12001,"getWifiList:system not support"
);
let err = new WifiFailImpl(getErrcode(12001)
);
option.fail?.(err)
option.complete?.(err)
}
...
...
@@ -181,11 +182,11 @@ export const getWifiList: GetWifiList = function (option: WifiOption) {
/* 获取wifi列表的回调
* note: 请在getWifiList方法的回调里调用该方法
*/
export const onGetWifiList: OnGetWifiList = function (callback: Uni
Wifi
Callback) {
export const onGetWifiList: OnGetWifiList = function (callback: Uni
GetWifiList
Callback) {
}
/*
/*
* 注销获取wifi列表的回调
*/
export const offGetWifiList: OffGetWifiList = function (callback: UniWifiCallback) {
...
...
@@ -193,12 +194,12 @@ export const offGetWifiList: OffGetWifiList = function (callback: UniWifiCallbac
}
/*
/*
* 获取当前连接的wifi信息
*/
export const getConnectedWifi: GetConnectedWifi = function (option: GetConnectedWifiOptions) {
if (UniWiFiModuleGloabInfo.alreadyStartWifi == false) {
let err = new UniError("uni-getConnectedWifi",12000,"getConnectedWifi:not init"
);
let err = new WifiFailImpl(getErrcode(12000)
);
option.fail?.(err)
option.complete?.(err)
} else{
...
...
@@ -207,7 +208,7 @@ export const getConnectedWifi: GetConnectedWifi = function (option: GetConnected
if (success == true) {
fetchConnectedWifiWithLocationPromise(option)
}else {
let err = new UniError("uni-getConnectedWifi",12007,"getConnectedWifi:user denied"
);
let err = new WifiFailImpl(getErrcode(12007)
);
option.fail?.(err)
option.complete?.(err)
}
...
...
@@ -218,50 +219,50 @@ export const getConnectedWifi: GetConnectedWifi = function (option: GetConnected
}
}
/*
/*
* 连接wifi
*/
export const connectWifi: ConnectWifi = function (option: WifiConnectOption) {
let err = new UniError("uni-connectWifi",12001,"connectWifi:system not support"
);
let err = new WifiFailImpl(getErrcode(12001)
);
option.fail?.(err)
option.complete?.(err)
}
/*
/*
* 连上wifi事件的监听函数
*/
export const onWifiConnected: OnWifiConnected = function (callback: UniWifiCallback) {
export const onWifiConnected: OnWifiConnected = function (callback: UniWifi
Result
Callback) {
}
/*
/*
* 连上wifi事件的监听函数, wifiInfo仅包含ssid
*/
export const onWifiConnectedWithPartialInfo: OnWifiConnectedWithPartialInfo = function (callback: UniWifi
Callback
) {
export const onWifiConnectedWithPartialInfo: OnWifiConnectedWithPartialInfo = function (callback: UniWifi
ResultCallbackWithPartialInfo
) {
}
/*
/*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/
export const offWifiConnected: OffWifiConnected = function (callback: UniWifiCallback | null) {
}
/*
/*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/
export const o
nOffWifiConnectedWithPartialInfo: OnOffWifiConnectedWithPartialInfo = function (callback: UniWifiCallback
| null) {
export const o
ffWifiConnectedWithPartialInfo: OffWifiConnectedWithPartialInfo = function (callback: UniWifiResultCallbackWithPartialInfo
| null) {
}
/*
/*
* 设置 wifiList 中 AP 的相关信息。在 onGetWifiList 回调后调用,iOS特有接口。
*/
export const setWifiList: SetWifiList = function (option: WifiOption) {
let err = new UniError("uni-setWifiList",12001,"setWifiList:system not support"
);
let err = new WifiFailImpl(getErrcode(12001)
);
option.fail?.(err)
option.complete?.(err)
}
\ No newline at end of file
}
uni_modules/uni-wifi/utssdk/index.d.ts
浏览文件 @
6afd901e
...
...
@@ -6,6 +6,7 @@ declare namespace UniNamespace {
type
WifiCompleteCallback
=
(
res
:
UniWifiComplete
)
=>
void
type
UniWifiCallback
=
()
=>
void
type
WifiErrorCode
=
1300002
interface
UniWifiInfo
{
...
...
@@ -27,31 +28,41 @@ declare namespace UniNamespace {
errCode
:
WifiErrorCode
}
interface
WifiConnectOption
{
interface
WifiConnectOption
{
SSID
:
string
|
null
;
BSSID
:
string
|
null
;
password
:
string
|
null
;
maunal
:
boolean
|
null
;
partialInfo
:
boolean
|
null
;
//ios不生效
success
?
:
WifiSuccessCallback
|
null
;
fail
?
:
WifiFailCallback
|
null
;
complete
?
:
WifiCompleteCallback
|
null
;
success
:
WifiSuccessCallback
|
null
;
fail
:
WifiFailCallback
|
null
;
complete
:
WifiCompleteCallback
|
null
;
}
interface
GetConnectedWifiOptions
{
partialInfo
:
boolean
|
null
;
success
?
:
WifiSuccessCallback
|
null
;
fail
?
:
WifiFailCallback
|
null
;
success
:
WifiSuccessCallback
|
null
;
fail
:
WifiFailCallback
|
null
;
complete
?:
WifiCompleteCallback
|
null
;
}
interface
WifiOption
{
success
?:
WifiSuccessCallback
|
null
,
fail
?:
WifiFailCallback
|
null
,
complete
?:
InstallApkCompleteCallback
|
null
success
:
WifiSuccessCallback
|
null
,
fail
:
WifiFailCallback
|
null
,
complete
:
InstallApkCompleteCallback
|
null
}
interface
UniWifiInfoWithPartialInfo
{
SSID
:
string
;
}
type
UniGetWifiListCallback
=
(
wifiInfo
:
UTSJSONObject
)
=>
void
type
UniWifiResultCallback
=
(
wifiInfo
:
UniWifiResult
)
=>
void
type
UniWifiResultCallbackWithPartialInfo
=
(
wifiInfo
:
UniWifiInfoWithPartialInfo
)
=>
void
}
declare
interface
Uni
{
...
...
@@ -207,7 +218,7 @@ declare interface Uni {
]
}
*/
onGetWifiList
(
callback
:
UniNamespace
.
Uni
Wifi
Callback
)
:
void
,
onGetWifiList
(
callback
:
UniNamespace
.
Uni
GetWifiList
Callback
)
:
void
,
/**
* 移除获取到 Wi-Fi 列表数据事件的监听函数。
*
...
...
@@ -279,7 +290,7 @@ declare interface Uni {
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onWifiConnected
(
callback
:
UniNamespace
.
UniWifiCallback
)
:
void
,
onWifiConnected
(
callback
:
UniNamespace
.
UniWifi
Result
Callback
)
:
void
,
/**
* 监听连接上 Wi-Fi 的事件。
*
...
...
@@ -303,7 +314,7 @@ declare interface Uni {
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onWifiConnectedWithPartialInfo
(
callback
:
UniNamespace
.
UniWifi
Callback
)
:
void
,
onWifiConnectedWithPartialInfo
(
callback
:
UniNamespace
.
UniWifi
ResultCallbackWithPartialInfo
)
:
void
,
/**
* 移除连接上 Wi-Fi 的事件的监听函数。
*
...
...
@@ -333,7 +344,7 @@ declare interface Uni {
* 移除连接上 Wi-Fi 的事件的监听函数。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#o
nO
ffWifiConnectedWithPartialInfo
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
* "android": {
...
...
@@ -352,7 +363,7 @@ declare interface Uni {
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
o
nOffWifiConnectedWithPartialInfo
(
callback
?:
UniNamespace
.
UniWifiCallback
)
:
void
,
o
ffWifiConnectedWithPartialInfo
(
callback
?:
UniNamespace
.
UniWifiResultCallbackWithPartialInfo
)
:
void
,
/**
* SetWifiList 暂未实现
*
...
...
uni_modules/uni-wifi/utssdk/interface.uts
浏览文件 @
6afd901e
...
...
@@ -83,7 +83,7 @@ export type OnWifiConnectedWithPartialInfo = (callback : UniWifiResultCallbackWi
export type OffWifiConnected = (callback : UniWifiCallback | null) => void
export type O
nOffWifiConnectedWithPartialInfo = (callback : UniWifiCallback
| null) => void
export type O
ffWifiConnectedWithPartialInfo = (callback : UniWifiResultCallbackWithPartialInfo
| null) => void
export type SetWifiList = (option : WifiOption) => void
...
...
@@ -382,7 +382,7 @@ interface Uni {
* 移除连接上 Wi-Fi 的事件的监听函数。
*
* @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#o
nO
ffWifiConnectedWithPartialInfo
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
* "android": {
...
...
@@ -401,7 +401,7 @@ interface Uni {
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
o
nOffWifiConnectedWithPartialInfo(callback : UniWifiCallback
| null) : void,
o
ffWifiConnectedWithPartialInfo(callback : UniWifiResultCallbackWithPartialInfo
| null) : void,
/**
* SetWifiList 暂未实现
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录