@@ -2,9 +2,9 @@ import Foundation
22#if os(iOS)
33import CoreTelephony
44import Reachability
5+ import SystemConfiguration. CaptiveNetwork
56#endif
67import Communicator
7- import NetworkExtension
88
99/// Wrapper around CoreTelephony, Reachability
1010public class ConnectivityWrapper {
@@ -59,18 +59,31 @@ public class ConnectivityWrapper {
5959 #if targetEnvironment(simulator)
6060 return " Simulator "
6161 #endif
62+
63+ guard let interfaces = CNCopySupportedInterfaces ( ) as? [ String ] else { return nil }
64+ for interface in interfaces {
65+ guard let interfaceInfo = CNCopyCurrentNetworkInfo ( interface as CFString ) as NSDictionary ? else {
66+ continue
67+ }
68+ return interfaceInfo [ kCNNetworkInfoKeySSID as String ] as? String
69+ }
6270 return nil
6371 }
6472 self . currentWiFiBSSID = {
65- nil
73+ guard let interfaces = CNCopySupportedInterfaces ( ) as? [ String ] else { return nil }
74+ for interface in interfaces {
75+ guard let interfaceInfo = CNCopyCurrentNetworkInfo ( interface as CFString ) as NSDictionary ? else {
76+ continue
77+ }
78+ return interfaceInfo [ kCNNetworkInfoKeyBSSID as String ] as? String
79+ }
80+ return nil
6681 }
6782 self . connectivityDidChangeNotification = { . reachabilityChanged }
6883 self . simpleNetworkType = { reachability? . getSimpleNetworkType ( ) ?? . unknown }
6984 self . cellularNetworkType = { reachability? . getNetworkType ( ) ?? . unknown }
7085 self . currentNetworkHardwareAddress = { nil }
7186 self . networkAttributes = { [ : ] }
72-
73- syncNetworkInformation ( )
7487 }
7588 #else
7689 init ( ) {
@@ -86,8 +99,6 @@ public class ConnectivityWrapper {
8699 self . cellularNetworkType = { . unknown }
87100 self . currentNetworkHardwareAddress = { nil }
88101 self . networkAttributes = { [ : ] }
89-
90- syncNetworkInformation ( )
91102 }
92103 #endif
93104
@@ -100,20 +111,4 @@ public class ConnectivityWrapper {
100111 CTTelephonyNetworkInfo ( ) . serviceCurrentRadioAccessTechnology
101112 }
102113 #endif
103-
104- private func syncNetworkInformation( ) {
105- NEHotspotNetwork . fetchCurrent { hotspotNetwork in
106- Current . Log
107- . verbose (
108- " Current SSID: \( String ( describing: hotspotNetwork? . ssid) ) , current BSSID: \( String ( describing: hotspotNetwork? . bssid) ) "
109- )
110- self . currentWiFiSSID = {
111- #if targetEnvironment(simulator)
112- return " Simulator "
113- #endif
114- return hotspotNetwork? . ssid
115- }
116- self . currentWiFiBSSID = { hotspotNetwork? . bssid }
117- }
118- }
119114}
0 commit comments