From b7cdd6c763ad18b0bb78e8ec68c0aacc3241988a Mon Sep 17 00:00:00 2001 From: lizhongyi Date: Fri, 25 Nov 2022 11:42:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20wifiInfomation=20=E6=8F=92?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 2 +- pages/SystemAPI/SystemAPI.vue | 6 + .../WifiInfomation/wifiInfomation.vue | 53 +++++++++ uni_modules/uni-wifiinformation/changelog.md | 0 uni_modules/uni-wifiinformation/package.json | 81 +++++++++++++ uni_modules/uni-wifiinformation/readme.md | 5 + .../utssdk/app-android/index.uts | 0 .../utssdk/app-ios/UTS.entitlements | 8 ++ .../utssdk/app-ios/index.uts | 109 ++++++++++++++++++ 9 files changed, 263 insertions(+), 1 deletion(-) create mode 100644 pages/SystemAPI/WifiInfomation/wifiInfomation.vue create mode 100644 uni_modules/uni-wifiinformation/changelog.md create mode 100644 uni_modules/uni-wifiinformation/package.json create mode 100644 uni_modules/uni-wifiinformation/readme.md create mode 100644 uni_modules/uni-wifiinformation/utssdk/app-android/index.uts create mode 100644 uni_modules/uni-wifiinformation/utssdk/app-ios/UTS.entitlements create mode 100644 uni_modules/uni-wifiinformation/utssdk/app-ios/index.uts diff --git a/manifest.json b/manifest.json index 5511eae..3362a99 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name" : "HelloUTS", - "appid" : "__UNI__70BE9D0", + "appid" : "__UNI__FB95CAB", "description" : "", "versionName" : "1.0.9", "versionCode" : "109", diff --git a/pages/SystemAPI/SystemAPI.vue b/pages/SystemAPI/SystemAPI.vue index 1092a32..f61e527 100644 --- a/pages/SystemAPI/SystemAPI.vue +++ b/pages/SystemAPI/SystemAPI.vue @@ -13,6 +13,7 @@ + @@ -65,6 +66,11 @@ url:'/pages/SystemAPI/ScreenListen/screenlisten' }) }, + gotoWifiInfomation(){ + uni.navigateTo({ + url:'/pages/SystemAPI/WifiInfomation/wifiInfomation' + }) + }, gotoAlert(){ uni.navigateTo({ url:'/pages/SystemAPI/Alert/alert' diff --git a/pages/SystemAPI/WifiInfomation/wifiInfomation.vue b/pages/SystemAPI/WifiInfomation/wifiInfomation.vue new file mode 100644 index 0000000..28ef4a0 --- /dev/null +++ b/pages/SystemAPI/WifiInfomation/wifiInfomation.vue @@ -0,0 +1,53 @@ + + + + + \ No newline at end of file diff --git a/uni_modules/uni-wifiinformation/changelog.md b/uni_modules/uni-wifiinformation/changelog.md new file mode 100644 index 0000000..e69de29 diff --git a/uni_modules/uni-wifiinformation/package.json b/uni_modules/uni-wifiinformation/package.json new file mode 100644 index 0000000..9ff8510 --- /dev/null +++ b/uni_modules/uni-wifiinformation/package.json @@ -0,0 +1,81 @@ +{ + "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 diff --git a/uni_modules/uni-wifiinformation/readme.md b/uni_modules/uni-wifiinformation/readme.md new file mode 100644 index 0000000..b364844 --- /dev/null +++ b/uni_modules/uni-wifiinformation/readme.md @@ -0,0 +1,5 @@ +# 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 diff --git a/uni_modules/uni-wifiinformation/utssdk/app-android/index.uts b/uni_modules/uni-wifiinformation/utssdk/app-android/index.uts new file mode 100644 index 0000000..e69de29 diff --git a/uni_modules/uni-wifiinformation/utssdk/app-ios/UTS.entitlements b/uni_modules/uni-wifiinformation/utssdk/app-ios/UTS.entitlements new file mode 100644 index 0000000..ba21fbd --- /dev/null +++ b/uni_modules/uni-wifiinformation/utssdk/app-ios/UTS.entitlements @@ -0,0 +1,8 @@ + + + + + com.apple.developer.networking.wifi-info + + + diff --git a/uni_modules/uni-wifiinformation/utssdk/app-ios/index.uts b/uni_modules/uni-wifiinformation/utssdk/app-ios/index.uts new file mode 100644 index 0000000..a0fdbd7 --- /dev/null +++ b/uni_modules/uni-wifiinformation/utssdk/app-ios/index.uts @@ -0,0 +1,109 @@ +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 +} -- GitLab