Skip to main content
edited tags
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
added 2 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Getting WifiWiFi SSID on iOS in Swift

I've seen a lot of Objective-C implementations but I'd like to do it in Swift.

I did it like this and it seems to work just fine. Does anyone have comments and/or improvements to make  ?

import SystemConfiguration

class EnvData: NSObject {

    class func getSSID() -> String {
        
        var currentSSID = ""
        
        let interfaces = CNCopySupportedInterfaces()
        
        if interfaces != nil {
            
            let interfacesArray = interfaces.takeRetainedValue() as [String]
            
            if interfacesArray.count > 0 {
                
                let interfaceName = interfacesArray[0] as String
                
                let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
                
                if unsafeInterfaceData != nil {
                    
                    let interfaceData = unsafeInterfaceData.takeRetainedValue() as Dictionary!
                    
                    currentSSID = interfaceData["SSID"] as String
                    
                } else {
                    
                    currentSSID = ""
                }
                
            } else {
                
                currentSSID = ""
            }
            
        } else {
            
            currentSSID = ""
        }
        
        return currentSSID
    }
}

Getting Wifi SSID on iOS in Swift

I've seen a lot of Objective-C implementations but I'd like to do it in Swift.

I did like this and it seems to work just fine. Does anyone have comments and/or improvements to make  ?

import SystemConfiguration

class EnvData: NSObject {

    class func getSSID() -> String {
        
        var currentSSID = ""
        
        let interfaces = CNCopySupportedInterfaces()
        
        if interfaces != nil {
            
            let interfacesArray = interfaces.takeRetainedValue() as [String]
            
            if interfacesArray.count > 0 {
                
                let interfaceName = interfacesArray[0] as String
                
                let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
                
                if unsafeInterfaceData != nil {
                    
                    let interfaceData = unsafeInterfaceData.takeRetainedValue() as Dictionary!
                    
                    currentSSID = interfaceData["SSID"] as String
                    
                } else {
                    
                    currentSSID = ""
                }
                
            } else {
                
                currentSSID = ""
            }
            
        } else {
            
            currentSSID = ""
        }
        
        return currentSSID
    }
}

Getting WiFi SSID on iOS in Swift

I've seen a lot of Objective-C implementations but I'd like to do it in Swift.

I did it like this and it seems to work just fine. Does anyone have comments and/or improvements to make?

import SystemConfiguration

class EnvData: NSObject {

    class func getSSID() -> String {
        
        var currentSSID = ""
        
        let interfaces = CNCopySupportedInterfaces()
        
        if interfaces != nil {
            
            let interfacesArray = interfaces.takeRetainedValue() as [String]
            
            if interfacesArray.count > 0 {
                
                let interfaceName = interfacesArray[0] as String
                
                let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
                
                if unsafeInterfaceData != nil {
                    
                    let interfaceData = unsafeInterfaceData.takeRetainedValue() as Dictionary!
                    
                    currentSSID = interfaceData["SSID"] as String
                    
                } else {
                    
                    currentSSID = ""
                }
                
            } else {
                
                currentSSID = ""
            }
            
        } else {
            
            currentSSID = ""
        }
        
        return currentSSID
    }
}
edited body; edited title
Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 160
  • 312

How to get wifi Getting Wifi SSID on iOS in swift?Swift

I've seen a lot of objectiveObjective-cC implementations but I'd like to do it in swiftSwift.

I did like this and it seems to work just fine. Does anyone have comments and/or improvements to make ?

import SystemConfiguration

class EnvData: NSObject {

    class func getSSID() -> String {
        
        var currentSSID = ""
        
        let interfaces = CNCopySupportedInterfaces()
        
        if interfaces != nil {
            
            let interfacesArray = interfaces.takeRetainedValue() as [String]
            
            if interfacesArray.count > 0 {
                
                let interfaceName = interfacesArray[0] as String
                
                let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
                
                if unsafeInterfaceData != nil {
                    
                    let interfaceData = unsafeInterfaceData.takeRetainedValue() as Dictionary!
                    
                    currentSSID = interfaceData["SSID"] as String
                    
                } else {
                    
                    currentSSID = ""
                }
                
            } else {
                
                currentSSID = ""
            }
            
        } else {
            
            currentSSID = ""
        }
        
        return currentSSID
    }
}

How to get wifi SSID on iOS in swift?

I've seen a lot of objective-c implementations but I'd like to do it in swift.

I did like this and it seems to work just fine. Does anyone have comments and/or improvements to make ?

import SystemConfiguration

class EnvData: NSObject {

    class func getSSID() -> String {
        
        var currentSSID = ""
        
        let interfaces = CNCopySupportedInterfaces()
        
        if interfaces != nil {
            
            let interfacesArray = interfaces.takeRetainedValue() as [String]
            
            if interfacesArray.count > 0 {
                
                let interfaceName = interfacesArray[0] as String
                
                let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
                
                if unsafeInterfaceData != nil {
                    
                    let interfaceData = unsafeInterfaceData.takeRetainedValue() as Dictionary!
                    
                    currentSSID = interfaceData["SSID"] as String
                    
                } else {
                    
                    currentSSID = ""
                }
                
            } else {
                
                currentSSID = ""
            }
            
        } else {
            
            currentSSID = ""
        }
        
        return currentSSID
    }
}

Getting Wifi SSID on iOS in Swift

I've seen a lot of Objective-C implementations but I'd like to do it in Swift.

I did like this and it seems to work just fine. Does anyone have comments and/or improvements to make ?

import SystemConfiguration

class EnvData: NSObject {

    class func getSSID() -> String {
        
        var currentSSID = ""
        
        let interfaces = CNCopySupportedInterfaces()
        
        if interfaces != nil {
            
            let interfacesArray = interfaces.takeRetainedValue() as [String]
            
            if interfacesArray.count > 0 {
                
                let interfaceName = interfacesArray[0] as String
                
                let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
                
                if unsafeInterfaceData != nil {
                    
                    let interfaceData = unsafeInterfaceData.takeRetainedValue() as Dictionary!
                    
                    currentSSID = interfaceData["SSID"] as String
                    
                } else {
                    
                    currentSSID = ""
                }
                
            } else {
                
                currentSSID = ""
            }
            
        } else {
            
            currentSSID = ""
        }
        
        return currentSSID
    }
}
Source Link
Alexis
  • 273
  • 1
  • 3
  • 7
Loading