Created
August 13, 2015 11:15
-
-
Save mlabraca/f053f6dad8403f0cf809 to your computer and use it in GitHub Desktop.
Get Wifi network information in swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import SystemConfiguration.CaptiveNetwork | |
class NetworkInfo { | |
func printSsidInfo { | |
if let ssidInfo = fetchSSIDInfo() as? [String:AnyObject], ssID = ssidInfo["SSID"] as? String { | |
println("SSID: \(ssID)") | |
} else { | |
println("SSID not found") | |
} | |
} | |
func fetchSSIDInfo() -> CFDictionary? { | |
if let | |
ifs = CNCopySupportedInterfaces().takeUnretainedValue() as? [String], | |
ifName = ifs.first, | |
info = CNCopyCurrentNetworkInfo((ifName as CFStringRef)) | |
{ | |
return info.takeUnretainedValue() | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment