提交 b7cdd6c7 编写于 作者: lizhongyi_'s avatar lizhongyi_

feat: add wifiInfomation 插件

上级 e941620d
{ {
"name" : "HelloUTS", "name" : "HelloUTS",
"appid" : "__UNI__70BE9D0", "appid" : "__UNI__FB95CAB",
"description" : "", "description" : "",
"versionName" : "1.0.9", "versionName" : "1.0.9",
"versionCode" : "109", "versionCode" : "109",
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<uni-collapse-item title="系统事件" :border="false"> <uni-collapse-item title="系统事件" :border="false">
<uni-list> <uni-list>
<uni-list-item @tap="gotoScreenListen" title="监听系统截屏" class="itemButton" :clickable="true" link/> <uni-list-item @tap="gotoScreenListen" title="监听系统截屏" class="itemButton" :clickable="true" link/>
<uni-list-item @tap="gotoWifiInfomation" title="获取当前wifi信息" class="itemButton" :clickable="true" link/>
</uni-list> </uni-list>
</uni-collapse-item> </uni-collapse-item>
</uni-collapse> </uni-collapse>
...@@ -65,6 +66,11 @@ ...@@ -65,6 +66,11 @@
url:'/pages/SystemAPI/ScreenListen/screenlisten' url:'/pages/SystemAPI/ScreenListen/screenlisten'
}) })
}, },
gotoWifiInfomation(){
uni.navigateTo({
url:'/pages/SystemAPI/WifiInfomation/wifiInfomation'
})
},
gotoAlert(){ gotoAlert(){
uni.navigateTo({ uni.navigateTo({
url:'/pages/SystemAPI/Alert/alert' url:'/pages/SystemAPI/Alert/alert'
......
<template>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<button @tap="getLocationPromise">获取定位权限</button>
<button @tap="getWifiInfo">获取WiFi信息</button>
</view>
</template>
<script>
import { getCurrentWifiInfo, requestLocationPromise } from '../../../uni_modules/uni-wifiinformation/utssdk/app-ios/index.uts'
export default {
data() {
return {
title:"获取当前连接wifi信息"
}
},
methods:{
getLocationPromise() {
requestLocationPromise((res):void => {
console.log(res)
uni.showToast({
title: res["message"],
icon: 'none'
})
})
},
getWifiInfo() {
/* iOS12之后获取wifi信息需要获取系统定位权限,否则获取到的wifi信息为空 */
requestLocationPromise((res):void => {
if (res["success"] == true) {
let wifiInfo = getCurrentWifiInfo()
if (wifiInfo != null) {
console.log(wifiInfo)
uni.showToast({
title: "当前wifi信息获取成功",
icon: 'none'
})
}
}
})
}
}
}
</script>
<style>
</style>
\ No newline at end of file
{
"id": "uni-wifiinformation",
"displayName": "uni-wifiinformation",
"version": "1.0.0",
"description": "uni-wifiinformation",
"keywords": [
"uni-wifiinformation"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
\ No newline at end of file
# uni-currentwifiinformation
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev)
\ No newline at end of file
<?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>
import { CLLocationManager, CLAuthorizationStatus, CLLocationManagerDelegate } from 'CoreLocation';
import { CaptiveNetwork, kCNNetworkInfoKeySSID, kCNNetworkInfoKeyBSSID } from 'SystemConfiguration.CaptiveNetwork';
import { NSArray, NSDictionary } from 'Foundation';
import { CFString } from 'CoreFoundation';
class CurrentWifiInfo {
wifiInterface: string = ""
SSID: string = ""
BSSID: string = ""
constructor(wifiInterface: string, ssid: string, bssid: string) {
this.wifiInterface = wifiInterface
this.SSID = ssid
this.BSSID = bssid
}
}
class LocationPromiseService implements CLLocationManagerDelegate {
static promiseCompletionHandler: UTSCallback[] = []
manager?: CLLocationManager = null
constructor(manager: CLLocationManager | null = null) {
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({success : true, message: "authorized success"})
})
} else if (status == CLAuthorizationStatus.notDetermined) {
manager.requestWhenInUseAuthorization()
} else if (status == CLAuthorizationStatus.denied) {
LocationPromiseService.promiseCompletionHandler.forEach((handler): void => {
handler({success : false, message: "user denied"})
})
}
}
requestPromise(completion: UTSCallback) {
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({success : true, message: "authorized success"})
} else if (status == CLAuthorizationStatus.denied) {
if (CLLocationManager.locationServicesEnabled() == false && this.initlizeManager() == true) {
this.manager!.requestWhenInUseAuthorization()
LocationPromiseService.promiseCompletionHandler.push(completion)
}
}
}
}
const locationPromiseService: LocationPromiseService = new LocationPromiseService()
export function requestLocationPromise (completion: UTSCallback) {
locationPromiseService.requestPromise(completion)
}
export function getCurrentWifiInfo (): CurrentWifiInfo | null {
let arr = CNCopySupportedInterfaces()
if (arr != null) {
let list = arr! as NSArray
let wifiInfo = new CurrentWifiInfo("", "", "")
let index = 0
let array = [1, 2, 3]
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.wifiInterface = interfaceName
wifiInfo.SSID = ssid
wifiInfo.BSSID = bssid
break;
}
}
index++
}
if (wifiInfo.BSSID.length > 0 && wifiInfo.SSID.length > 0) {
return wifiInfo
}
}
return null
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册