I have a function that detects the current SSID from the user. Unfortunately this doesn't work anymore with iOS 12. This means it just jumps over the if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
part. Maybe it's just a bug or it's deprecated. I've found nothing on Apple Docs.
On older iOS 11, 10, and 9 devices, it works well.
Here's my Code:
func getWiFiSsid() -> String? {
if let interfaces = CNCopySupportedInterfaces() as NSArray? {
for interface in interfaces {
if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
}
}
}
return ssid
}
if let
to cast to an optional makes no sense. And don't useNSArray
orNSDictionary
in Swift. – SaddenCNCopyCurrentNetworkInfo
: "To use this function in iOS 12 and later, enable the Add WiFi Information capability for your app in Xcode. When you enable this capability, Xcode automatically adds the Add WiFi Information entitlement to your entitlements file and adds the corresponding feature to your App ID." – Sadden