@capgo/capacitor-wifi 8.1.8 → 8.1.9
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.
|
@@ -44,7 +44,7 @@ import java.util.List;
|
|
|
44
44
|
)
|
|
45
45
|
public class CapacitorWifiPlugin extends Plugin {
|
|
46
46
|
|
|
47
|
-
private final String pluginVersion = "8.1.
|
|
47
|
+
private final String pluginVersion = "8.1.9";
|
|
48
48
|
|
|
49
49
|
private WifiManager wifiManager;
|
|
50
50
|
private ConnectivityManager connectivityManager;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import Capacitor
|
|
3
3
|
import NetworkExtension
|
|
4
|
-
import SystemConfiguration.CaptiveNetwork
|
|
5
4
|
import CoreLocation
|
|
6
5
|
|
|
7
6
|
@objc(CapacitorWifiPlugin)
|
|
8
7
|
public class CapacitorWifiPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
9
|
-
private let pluginVersion: String = "8.1.
|
|
8
|
+
private let pluginVersion: String = "8.1.9"
|
|
10
9
|
public let identifier = "CapacitorWifiPlugin"
|
|
11
10
|
public let jsName = "CapacitorWifi"
|
|
12
11
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -88,14 +87,16 @@ public class CapacitorWifiPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
88
87
|
|
|
89
88
|
if let ssid = ssid {
|
|
90
89
|
hotspotManager?.removeConfiguration(forSSID: ssid)
|
|
90
|
+
call.resolve()
|
|
91
91
|
} else {
|
|
92
|
-
// Disconnect from current network by
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
// Disconnect from current network by fetching current SSID asynchronously
|
|
93
|
+
Task {
|
|
94
|
+
if let currentSSID = await fetchCurrentNetwork()?.ssid {
|
|
95
|
+
self.hotspotManager?.removeConfiguration(forSSID: currentSSID)
|
|
96
|
+
}
|
|
97
|
+
call.resolve()
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
|
-
|
|
98
|
-
call.resolve()
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
@objc func getAvailableNetworks(_ call: CAPPluginCall) {
|
|
@@ -142,33 +143,40 @@ public class CapacitorWifiPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
@objc func getSsid(_ call: CAPPluginCall) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
Task {
|
|
147
|
+
if let ssid = await fetchCurrentNetwork()?.ssid {
|
|
148
|
+
call.resolve(["ssid": ssid])
|
|
149
|
+
} else {
|
|
150
|
+
call.reject("Failed to get SSID")
|
|
151
|
+
}
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
154
|
|
|
152
155
|
@objc func getWifiInfo(_ call: CAPPluginCall) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
Task {
|
|
157
|
+
guard let network = await fetchCurrentNetwork() else {
|
|
158
|
+
call.reject("Failed to get SSID")
|
|
159
|
+
return
|
|
160
|
+
}
|
|
157
161
|
|
|
158
|
-
|
|
162
|
+
var result: [String: Any] = [
|
|
163
|
+
"ssid": network.ssid,
|
|
164
|
+
"bssid": network.bssid
|
|
165
|
+
]
|
|
159
166
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
+
// Get IP Address
|
|
168
|
+
if let ipAddress = self.getIPAddress() {
|
|
169
|
+
result["ip"] = ipAddress
|
|
170
|
+
} else {
|
|
171
|
+
call.reject("Failed to get IP address")
|
|
172
|
+
return
|
|
173
|
+
}
|
|
167
174
|
|
|
168
|
-
|
|
169
|
-
|
|
175
|
+
// Note: frequency, linkSpeed, and signalStrength are not available on iOS
|
|
176
|
+
// through public APIs, so we only return ssid, bssid, and ip
|
|
170
177
|
|
|
171
|
-
|
|
178
|
+
call.resolve(result)
|
|
179
|
+
}
|
|
172
180
|
}
|
|
173
181
|
|
|
174
182
|
@objc func isEnabled(_ call: CAPPluginCall) {
|
|
@@ -197,12 +205,15 @@ public class CapacitorWifiPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
197
205
|
|
|
198
206
|
// MARK: - Helper Methods
|
|
199
207
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
208
|
+
/// Fetches the current Wi-Fi network asynchronously.
|
|
209
|
+
/// NEHotspotNetwork.fetchCurrent uses a completion handler (async), so we bridge it
|
|
210
|
+
/// with withCheckedContinuation to avoid returning nil before the callback fires.
|
|
211
|
+
private func fetchCurrentNetwork() async -> NEHotspotNetwork? {
|
|
212
|
+
await withCheckedContinuation { continuation in
|
|
213
|
+
NEHotspotNetwork.fetchCurrent { network in
|
|
214
|
+
continuation.resume(returning: network)
|
|
215
|
+
}
|
|
204
216
|
}
|
|
205
|
-
return currentSSID
|
|
206
217
|
}
|
|
207
218
|
|
|
208
219
|
private func getIPAddress() -> String? {
|
|
@@ -236,7 +247,8 @@ public class CapacitorWifiPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
236
247
|
}
|
|
237
248
|
|
|
238
249
|
private func getLocationPermissionStatus() -> String {
|
|
239
|
-
|
|
250
|
+
let manager = CLLocationManager()
|
|
251
|
+
switch manager.authorizationStatus {
|
|
240
252
|
case .authorizedAlways, .authorizedWhenInUse:
|
|
241
253
|
return "granted"
|
|
242
254
|
case .denied, .restricted:
|