Gianluca
Gianluca

Reputation: 143

Swift - get wifi security type

Is there any way to detect if the wifi connection is secured using swift? is it possible to get the type security on the wifi? wpa, wep etc.

I get the ssid name in this way:

func getWiFiSsid() -> String? {

var ssid: 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
                break
       }
   }
}
return ssid
}

Thanks.

Upvotes: 12

Views: 3671

Answers (3)

yycking
yycking

Reputation: 1331

Use NEHotspotNetwork in iOS15.

NEHotspotNetwork.fetchCurrent { network in
   print(network.securityType)
}

Upvotes: 2

刘俊利
刘俊利

Reputation: 358

Not possible to get WiFi(current connected) security in CNCopySupportedInterfaces

Go to see the detail:

https://forums.developer.apple.com/message/342349#342349

Upvotes: 1

Can
Can

Reputation: 4736

Some of Apple's frameworks are out of reach of the everyday AppStore developer. These frameworks are namely private frameworks.

They are present inside iOS but just not documented like the other frameworks(CoreLocation, UIKit, etc.). With reverse engineering methods, one can learn how to use those frameworks but most importantly, since they're forbidden of use, if you submit an app which makes use of a private framework to the AppStore, it will surely be rejected!

The API for extracting Wi-Fi security type is included in a private framework; therefore you can't use it an AppStore app.

Although if you want to experiment with private frameworks, for personal usage, you can visit here where you will find the whole list of the private frameworks.

Keep in mind that their usage is not straightforward. If you want a starter, here is BeeTee, which demonstrates how to make use of the private framework BluetoothManager.

Upvotes: 2

Related Questions