获取当前的wifi SSID

version: swift 2.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
extension UIDevice {

/// wifi SSID
static var WIFISSID: String {
let interfaces: CFArray? = CNCopySupportedInterfaces()
if interfaces == nil { return "" }

let if0: UnsafePointer<Void>? = CFArrayGetValueAtIndex(interfaces, 0)
if if0 == nil { return "" }

let interfaceName: CFStringRef = unsafeBitCast(if0!, CFStringRef.self)
let dictionary = CNCopyCurrentNetworkInfo(interfaceName) as NSDictionary?
if dictionary == nil { return "" }

if let SSID = dictionary?[kCNNetworkInfoKeySSID as String] as? String {
return SSID
}
return ""
}


}
坚持原创技术分享,您的支持将鼓励我继续创作!