@capgo/capacitor-wifi 8.1.7 → 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.
@@ -30,7 +30,7 @@ android {
30
30
  buildTypes {
31
31
  release {
32
32
  minifyEnabled false
33
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
34
34
  }
35
35
  }
36
36
  lintOptions {
@@ -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.7";
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.7"
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 getting current SSID
93
- if let currentSSID = getCurrentSSID() {
94
- hotspotManager?.removeConfiguration(forSSID: currentSSID)
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
- if let ssid = getCurrentSSID() {
146
- call.resolve(["ssid": ssid])
147
- } else {
148
- call.reject("Failed to get SSID")
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
- guard let ssid = getCurrentSSID() else {
154
- call.reject("Failed to get SSID")
155
- return
156
- }
156
+ Task {
157
+ guard let network = await fetchCurrentNetwork() else {
158
+ call.reject("Failed to get SSID")
159
+ return
160
+ }
157
161
 
158
- var result: [String: Any] = ["ssid": ssid]
162
+ var result: [String: Any] = [
163
+ "ssid": network.ssid,
164
+ "bssid": network.bssid
165
+ ]
159
166
 
160
- // Get IP Address
161
- if let ipAddress = getIPAddress() {
162
- result["ip"] = ipAddress
163
- } else {
164
- call.reject("Failed to get IP address")
165
- return
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
- // Note: BSSID, frequency, linkSpeed, and signalStrength are not available on iOS
169
- // through public APIs, so we only return ssid and ip
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
- call.resolve(result)
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
- private func getCurrentSSID() -> String? {
201
- var currentSSID: String?
202
- NEHotspotNetwork.fetchCurrent { network in
203
- currentSSID = network?.ssid
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
- switch CLLocationManager.authorizationStatus() {
250
+ let manager = CLLocationManager()
251
+ switch manager.authorizationStatus {
240
252
  case .authorizedAlways, .authorizedWhenInUse:
241
253
  return "granted"
242
254
  case .denied, .restricted:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-wifi",
3
- "version": "8.1.7",
3
+ "version": "8.1.9",
4
4
  "description": "Manage WiFi connectivity for your Capacitor app",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",