ln-capacitor-wifi 0.0.13 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/Plugin/WifiPlugin.swift +102 -4
- package/package.json +1 -1
|
@@ -1,18 +1,116 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import Capacitor
|
|
3
|
+
import SystemConfiguration.CaptiveNetwork
|
|
4
|
+
import CoreLocation
|
|
5
|
+
|
|
6
|
+
struct WifiEntry {
|
|
7
|
+
var bssid: String
|
|
8
|
+
var ssid: String = "[HIDDEN_SSID]"
|
|
9
|
+
var level: Int = -1
|
|
10
|
+
var isCurrentWify: Bool = false
|
|
11
|
+
var capabilities: [String] = []
|
|
12
|
+
}
|
|
3
13
|
|
|
4
14
|
/**
|
|
5
15
|
* Please read the Capacitor iOS Plugin Development Guide
|
|
6
16
|
* here: https://capacitorjs.com/docs/plugins/ios
|
|
7
17
|
*/
|
|
8
18
|
@objc(WifiPlugin)
|
|
9
|
-
public class WifiPlugin: CAPPlugin {
|
|
10
|
-
|
|
19
|
+
public class WifiPlugin: CAPPlugin, CLLocationManagerDelegate {
|
|
20
|
+
|
|
21
|
+
var _currentCall: CAPPluginCall?
|
|
22
|
+
var _locationManager: CLLocationManager = CLLocationManager()
|
|
23
|
+
|
|
24
|
+
private let wifi = Wifi()
|
|
25
|
+
|
|
26
|
+
public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
|
|
27
|
+
var locationState = "granted"
|
|
28
|
+
|
|
29
|
+
let call: CAPPluginCall = _currentCall! as CAPPluginCall
|
|
30
|
+
_currentCall = nil
|
|
31
|
+
|
|
32
|
+
if status != .authorizedAlways && status != .authorizedWhenInUse {
|
|
33
|
+
locationState = "denied"
|
|
34
|
+
} else if status == .restricted {
|
|
35
|
+
locationState = "prompt"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
call.resolve([
|
|
39
|
+
"LOCATION": locationState,
|
|
40
|
+
"NETWORK": "granted"
|
|
41
|
+
])
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@objc override public func checkPermissions(_ call: CAPPluginCall) {
|
|
45
|
+
|
|
46
|
+
var locationState = "granted"
|
|
47
|
+
|
|
48
|
+
let locationStatus = CLLocationManager.authorizationStatus()
|
|
49
|
+
if locationStatus != .authorizedAlways && locationStatus != .authorizedWhenInUse {
|
|
50
|
+
locationState = "denied"
|
|
51
|
+
} else if locationStatus == .restricted {
|
|
52
|
+
locationState = "prompt"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
call.resolve([
|
|
56
|
+
"LOCATION": locationState,
|
|
57
|
+
"NETWORK": "granted"
|
|
58
|
+
])
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@objc override public func requestPermissions(_ call: CAPPluginCall) {
|
|
62
|
+
|
|
63
|
+
let locationStatus = CLLocationManager.authorizationStatus()
|
|
64
|
+
if locationStatus != .authorizedAlways && locationStatus != .authorizedWhenInUse {
|
|
65
|
+
_currentCall = call
|
|
66
|
+
_locationManager.delegate = self
|
|
67
|
+
_locationManager.requestWhenInUseAuthorization()
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
call.resolve([
|
|
72
|
+
"LOCATION": "granted",
|
|
73
|
+
"NETWORK": "granted"
|
|
74
|
+
])
|
|
75
|
+
}
|
|
11
76
|
|
|
12
|
-
@objc func
|
|
77
|
+
@objc func connectToWifiBySsidAndPassword(_ call: CAPPluginCall) {
|
|
13
78
|
let value = call.getString("value") ?? ""
|
|
14
79
|
call.resolve([
|
|
15
|
-
"value":
|
|
80
|
+
"value": wifi.echo(value)
|
|
16
81
|
])
|
|
17
82
|
}
|
|
83
|
+
|
|
84
|
+
@objc func scanWifi(_ call: CAPPluginCall) {
|
|
85
|
+
if let interfaces: NSArray = CNCopySupportedInterfaces() {
|
|
86
|
+
var wifis = [WifiEntry]()
|
|
87
|
+
|
|
88
|
+
for interface in interfaces {
|
|
89
|
+
let interfaceName = interface as! String
|
|
90
|
+
|
|
91
|
+
if let dict = CNCopyCurrentNetworkInfo(interfaceName as CFString) as NSDictionary? {
|
|
92
|
+
let networkInfo = WifiEntry(
|
|
93
|
+
bssid: dict[kCNNetworkInfoKeyBSSID as String] as? String ?? "",
|
|
94
|
+
ssid: dict[kCNNetworkInfoKeySSID as String] as? String ?? "[HIDDEN_SSID]",
|
|
95
|
+
level: -1,
|
|
96
|
+
isCurrentWify: false,
|
|
97
|
+
capabilities: [String]()
|
|
98
|
+
)
|
|
99
|
+
wifis.append(networkInfo)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
call.resolve([
|
|
104
|
+
"wifis": wifis
|
|
105
|
+
] as PluginCallResultData)
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let wifis: [String] = []
|
|
110
|
+
call.resolve(["wifis": wifis])
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@objc func getCurrentWifi(_ call: CAPPluginCall) {
|
|
114
|
+
call.resolve(["currentWifi": ""])
|
|
115
|
+
}
|
|
18
116
|
}
|
package/package.json
CHANGED