Update API to access current Wi-Fi SSID
This commit is contained in:
parent
1c4c21fa22
commit
44844cfd9c
|
@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Changed
|
||||
|
||||
- Update API to access current Wi-Fi SSID.
|
||||
|
||||
## 3.0.0 (2020-11-15)
|
||||
|
||||
### Added
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = "TunnelKit"
|
||||
s.version = "3.0.1"
|
||||
s.version = "3.1.0"
|
||||
s.summary = "Non-official OpenVPN client for Apple platforms."
|
||||
|
||||
s.homepage = "https://github.com/passepartoutvpn/tunnelkit"
|
||||
|
|
|
@ -35,7 +35,12 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
#if os(iOS)
|
||||
import NetworkExtension
|
||||
import SystemConfiguration.CaptiveNetwork
|
||||
#else
|
||||
import CoreWLAN
|
||||
#endif
|
||||
import SwiftyBeaver
|
||||
|
||||
private let log = SwiftyBeaver.self
|
||||
|
@ -80,9 +85,14 @@ public class InterfaceObserver: NSObject {
|
|||
}
|
||||
|
||||
private func fireWifiChangeObserver() {
|
||||
let currentWifiName = currentWifiNetworkName()
|
||||
if (currentWifiName != lastWifiName) {
|
||||
if let current = currentWifiName {
|
||||
InterfaceObserver.fetchCurrentSSID {
|
||||
self.fireWifiChange(withSSID: $0)
|
||||
}
|
||||
}
|
||||
|
||||
private func fireWifiChange(withSSID ssid: String?) {
|
||||
if ssid != lastWifiName {
|
||||
if let current = ssid {
|
||||
log.debug("SSID is now '\(current.maskedDescription)'")
|
||||
if let last = lastWifiName, (current != last) {
|
||||
queue?.async {
|
||||
|
@ -93,7 +103,7 @@ public class InterfaceObserver: NSObject {
|
|||
log.debug("SSID is null")
|
||||
}
|
||||
}
|
||||
lastWifiName = currentWifiName
|
||||
lastWifiName = ssid
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,20 +111,32 @@ public class InterfaceObserver: NSObject {
|
|||
|
||||
- Returns: The current Wi-Fi SSID if any.
|
||||
**/
|
||||
public func currentWifiNetworkName() -> String? {
|
||||
public static func fetchCurrentSSID(completionHandler: @escaping (String?) -> Void) {
|
||||
#if os(iOS)
|
||||
// if #available(iOS 14.0, *) {
|
||||
// NEHotspotNetwork.fetchCurrent {
|
||||
// completionHandler($0?.ssid)
|
||||
// }
|
||||
// } else {
|
||||
guard let interfaceNames = CNCopySupportedInterfaces() as? [CFString] else {
|
||||
return nil
|
||||
completionHandler(nil)
|
||||
return
|
||||
}
|
||||
for name in interfaceNames {
|
||||
guard let iface = CNCopyCurrentNetworkInfo(name) as? [String: Any] else {
|
||||
continue
|
||||
}
|
||||
if let ssid = iface["SSID"] as? String {
|
||||
return ssid
|
||||
completionHandler(ssid)
|
||||
return
|
||||
}
|
||||
}
|
||||
completionHandler(nil)
|
||||
// }
|
||||
#else
|
||||
let client = CWWiFiClient.shared()
|
||||
let ssid = client.interfaces()?.compactMap { $0.ssid() }.first
|
||||
completionHandler(ssid)
|
||||
#endif
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,11 @@
|
|||
|
||||
import NetworkExtension
|
||||
import SwiftyBeaver
|
||||
#if os(iOS)
|
||||
import SystemConfiguration.CaptiveNetwork
|
||||
#else
|
||||
import CoreWLAN
|
||||
#endif
|
||||
import __TunnelKitCore
|
||||
|
||||
private let log = SwiftyBeaver.self
|
||||
|
@ -90,8 +95,6 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider {
|
|||
|
||||
private let memoryLog = MemoryDestination()
|
||||
|
||||
private let observer = InterfaceObserver()
|
||||
|
||||
private let tunnelQueue = DispatchQueue(label: OpenVPNTunnelProvider.description(), qos: .utility)
|
||||
|
||||
private let prngSeedLength = 64
|
||||
|
@ -829,12 +832,14 @@ extension OpenVPNTunnelProvider {
|
|||
}
|
||||
|
||||
private func logCurrentSSID() {
|
||||
if let ssid = observer.currentWifiNetworkName() {
|
||||
InterfaceObserver.fetchCurrentSSID {
|
||||
if let ssid = $0 {
|
||||
log.debug("Current SSID: '\(ssid.maskedDescription)'")
|
||||
} else {
|
||||
log.debug("Current SSID: none (disconnected from WiFi)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// private func anyPointer(_ object: Any?) -> UnsafeMutableRawPointer {
|
||||
// let anyObject = object as AnyObject
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.3.0</string>
|
||||
<string>3.1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.3.0</string>
|
||||
<string>3.1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.3.0</string>
|
||||
<string>3.1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
|
|
Loading…
Reference in New Issue