Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
6cb7a16a
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看板
提交
6cb7a16a
编写于
11月 28, 2022
作者:
lizhongyi_
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 实现iOS uni-wifi插件的getConnectedWifi接口,其余接口空实现
上级
2f876e63
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
350 addition
and
0 deletion
+350
-0
.hbuilderx/launcher/hx_iOS_resign.json
.hbuilderx/launcher/hx_iOS_resign.json
+1
-0
uni_modules/uni-wifi/utssdk/app-ios/Info.plist
uni_modules/uni-wifi/utssdk/app-ios/Info.plist
+8
-0
uni_modules/uni-wifi/utssdk/app-ios/UTS.entitlements
uni_modules/uni-wifi/utssdk/app-ios/UTS.entitlements
+8
-0
uni_modules/uni-wifi/utssdk/app-ios/config.json
uni_modules/uni-wifi/utssdk/app-ios/config.json
+9
-0
uni_modules/uni-wifi/utssdk/app-ios/index.uts
uni_modules/uni-wifi/utssdk/app-ios/index.uts
+324
-0
未找到文件。
.hbuilderx/launcher/hx_iOS_resign.json
0 → 100644
浏览文件 @
6cb7a16a
{
"index"
:
1
}
\ No newline at end of file
uni_modules/uni-wifi/utssdk/app-ios/Info.plist
0 → 100644
浏览文件 @
6cb7a16a
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist
version=
"1.0"
>
<dict>
<key>
NSLocationWhenInUseUsageDescription
</key>
<string>
使用期间获取位置权限
</string>
</dict>
</plist>
\ No newline at end of file
uni_modules/uni-wifi/utssdk/app-ios/UTS.entitlements
0 → 100644
浏览文件 @
6cb7a16a
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist
version=
"1.0"
>
<dict>
<key>
com.apple.developer.networking.wifi-info
</key>
<true/>
</dict>
</plist>
\ No newline at end of file
uni_modules/uni-wifi/utssdk/app-ios/config.json
0 → 100644
浏览文件 @
6cb7a16a
{
"frameworks"
:
[
"CoreLocation"
,
"SystemConfiguration"
],
"deploymentTarget"
:
"9.0"
,
"validArchitectures"
:
[
"arm64"
,
"armv7"
]
}
\ No newline at end of file
uni_modules/uni-wifi/utssdk/app-ios/index.uts
浏览文件 @
6cb7a16a
import { CLLocationManager, CLAuthorizationStatus, CLLocationManagerDelegate } from 'CoreLocation'
import { CaptiveNetwork, kCNNetworkInfoKeySSID, kCNNetworkInfoKeyBSSID } from 'SystemConfiguration.CaptiveNetwork';
import { JSONEncoder, NSArray, NSDictionary } from 'Foundation';
import { CFString } from 'CoreFoundation';
import { UIDevice } from 'UIKit';
/**
* 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
}
type GetLocationPromiseOptions = {
complete?: (res: boolean) => void
}
type UniWifiInfo = {
SSID: string;
BSSID: string;
secure: boolean;
signalStrength: number;
frequency: number;
}
/*
* 对外暴露的wifi信息类
*/
// class UniWifiInfo {
// SSID: string;
// BSSID: string;
// secure: boolean;
// signalStrength: number;
// frequency: number;
// constructor(SSID: string, BSSID: string, secure: boolean, signalStrength: number, frequency: number) {
// this.SSID = SSID
// this.BSSID = BSSID
// this.secure = secure
// this.signalStrength = signalStrength
// this.frequency = frequency
// }
// }
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()
this.manager!.delegate = this
}
return true
}
locationManager(manager: CLLocationManager, status: CLAuthorizationStatus) {
if (status == CLAuthorizationStatus.authorizedAlways || status == CLAuthorizationStatus.authorizedWhenInUse) {
LocationPromiseService.promiseCompletionHandler.forEach((handler): void => {
handler(true)
})
} else if (status == CLAuthorizationStatus.notDetermined) {
manager.requestWhenInUseAuthorization()
} else if (status == CLAuthorizationStatus.denied) {
LocationPromiseService.promiseCompletionHandler.forEach((handler): void => {
handler(false)
})
}
}
locationManagerDidChangeAuthorization(manager: CLLocationManager) {
}
locationManagerDidPauseLocationUpdates(manager: CLLocationManager) {
}
locationManagerDidResumeLocationUpdates(manager: CLLocationManager) {
}
locationManagerShouldDisplayHeadingCalibration(manager: CLLocationManager): boolean {
return true
}
requestPromise(@escaping completion: (res: boolean)=>void) {
let status: CLAuthorizationStatus = CLLocationManager.authorizationStatus()
if (status == CLAuthorizationStatus.notDetermined) {
if (this.initlizeManager() == true) {
this.manager!.requestWhenInUseAuthorization()
LocationPromiseService.promiseCompletionHandler.push(completion)
}
} else if (status == CLAuthorizationStatus.authorizedAlways || status == CLAuthorizationStatus.authorizedWhenInUse) {
completion(true)
} else if (status == CLAuthorizationStatus.denied) {
if (CLLocationManager.locationServicesEnabled() == false && this.initlizeManager() == true) {
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) {
let arr = CNCopySupportedInterfaces()
let wifiInfo = new UniWifiInfo()
if (arr != null) {
let list = arr! as NSArray
let index = 0
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 BSSID = dict[kCNNetworkInfoKeyBSSID as string]
if (SSID != null && BSSID != null) {
let ssid = SSID! as string
let bssid = BSSID! as string
wifiInfo.SSID = ssid
wifiInfo.BSSID = bssid
wifiInfo.signalStrength = 0
wifiInfo.frequency = 0
break;
}
}
index++
}
if (wifiInfo.BSSID.length > 0 && wifiInfo.SSID.length > 0) {
let res = {
errCode: 0,
errMsg: "getConnectedWifi:success",
wifi: wifiInfo,
}
option.success?.(res)
option.complete?.(res)
}else {
option.fail?.({errCode: 12000, errMsg: "current wifi is null"})
option.complete?.({errCode: 12000, errMsg: "current wifi is null"})
}
}else {
option.fail?.({errCode: 12000, errMsg: "current wifi is null"})
option.complete?.({errCode: 12000, errMsg: "current wifi is null"})
}
}
/* =================================== 对外暴露的接口 ==============================================*/
/*
* 初始化wifi模块
*/
export function startWifi(option: WifiOption) {
let res = {
errCode: 12001,
errMsg: "system not support"
}
option.fail?.(res)
option.complete?.(res)
}
/*
* 停止wifi模块
*/
export function stopWifi() {
LocationPromiseService.promiseCompletionHandler = []
}
/*
* 获取wifi列表, 在调用之前需要引导用户跳转到系统设置-WIFI设置页面,系统搜索周边wifi后app才能接收到回调
*/
export function getWifiList(option: WifiOption) {
let res = {
errCode: 12001,
errMsg: "system not support"
}
option.fail?.(res)
option.complete?.(res)
}
/* 获取wifi列表的回调
* note: 请在getWifiList方法的回调里调用该方法
*/
export function onGetWifiList(callback: UTSCallback) {
}
/*
* 注销获取wifi列表的回调
*/
export function offGetWifiList(callback: UTSCallback) {
}
/*
* 获取当前连接的wifi信息
*/
export function getConnectedWifi(option: GetConnectedWifiOptions) {
if (UIDevice.current.systemVersion >= "13.0") {
requestLocationPromise((success) => {
if (success == true) {
fetchConnectedWifiWithLocationPromise(option)
}else {
let res = {
errCode: 12010,
errMsg: "have no location promise"
}
option.fail?.(res)
option.complete?.(res)
}
})
} else{
fetchConnectedWifiWithLocationPromise(option)
}
}
/*
* 连接wifi
*/
export function connectWifi(option: WifiConnectOption) {
let res = {
errCode: 12001,
errMsg: "system not support"
}
option.fail?.(res)
option.complete?.(res)
}
/*
* 连上wifi事件的监听函数
*/
export function onWifiConnected(callback: UTSCallback) {
}
/*
* 连上wifi事件的监听函数, wifiInfo仅包含ssid
*/
export function onWifiConnectedWithPartialInfo(callback: UTSCallback) {
}
/*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/
export function offWifiConnected(callback: UTSCallback | null) {
}
/*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/
export function onOffWifiConnectedWithPartialInfo(callback: UTSCallback | null) {
}
/*
* 设置 wifiList 中 AP 的相关信息。在 onGetWifiList 回调后调用,iOS特有接口。
*/
export function setWifiList(option: WifiOption) {
let res = {
errCode: 12001,
errMsg: "system not support"
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录