SSID(Service Set Identifier),許多人認爲能夠將SSID寫成ESSID,其實否則,SSID是個籠統的概念,包含了ESSID和BSSID,用來區分不一樣的網絡,最多能夠有32個字符,無線網卡設置了不一樣的SSID就能夠進入不一樣網絡,SSID一般由AP廣播出來,經過XP自帶的掃描功能能夠查看當前區域內的SSID。出於安全考慮能夠不廣播SSID,此時用戶就要手工設置SSID才能進入相應的網絡。簡單說,SSID就是一個局域網的名稱,只有設置爲名稱相同SSID的值的電腦才能互相通訊。安全
import Foundation import SystemConfiguration //在 head.h 文件中導入 #import public class CommonUtil{ class func getMAC()->(success:Bool,ssid:String,mac:String){ iflet cfa:NSArray = CNCopySupportedInterfaces() { for x in cfa { iflet dict = CFBridgingRetain(CNCopyCurrentNetworkInfo(x as! CFString)) { let ssid = dict["SSID"]! let mac = dict["BSSID"]! return (true,ssid as! String,mac as! String) } } } return (false,"","") } class func getWifiSSID() -> String? { let interfaces: CFArray! = CNCopySupportedInterfaces()//?.takeRetainedValue() if interfaces == nil { return nil } let if0: UnsafePointer<<span se-mark="1">Void>? = CFArrayGetValueAtIndex(interfaces, 0) if if0 == nil { return nil } let interfaceName: CFStringRef = unsafeBitCast(if0!, CFStringRef.self) // let dictionary = CNCopyCurrentNetworkInfo(interfaceName)//?.takeRetainedValue() as NSDictionary? let dictionary = CNCopyCurrentNetworkInfo(interfaceName) as NSDictionary? if dictionary == nil { return nil } return dictionary?[kCNNetworkInfoKeySSIDasString] as? String } }