현재 연결된 WiFi의 SSID값을 받아와서 내가 연결하려한SSID와 같은지 비교해서

앱내에서 연결이 됐는지 확인하는 예제를 만들고 있었으나,

func currentSSIDs() -> [String] {
    guard let interfaces = CNCopySupportedInterfaces() as? [String] else {
        return []
    }
    return interfaces.compactMap { interfaceName in
        guard let info = CNCopyCurrentNetworkInfo(interfaceName as CFString) as? [String:AnyObject] else {
        	print("Point 0")
            return nil
        }
        guard let ssid = info[kCNNetworkInfoKeySSID as String] as? String else {
        	print("Point 1")
            return nil
        }
        return ssid
    }
}

ps. 해당소스는 https://codeday.me/ko/qa/20190625/886103.html 를 보고 살짝 바꾼 코드이다.

(iOS11 이상부터?  단순 Nil값 제거는 flatMap 대신 compactMap 을 쓰는걸 권장하고있다)

 

currentSSIDs 의 값이 항상 nil이 나오고

console에 Point 0가 찍힌다.

 

처음에는 뭔가 키라던가 변경되어 값을 잘못 참조하고있는줄 알았다.

그렇게 키값 위주로 검색해보던중 우연찮게

잘못된곳은 그곳이 아니라는걸 알게되었고

문제는 아래 스택오버플로우의 글과 같았다.

 

https://stackoverflow.com/questions/50767946/systemconfiguration-captivenetwork-doesnt-work-on-ios-12 

 

테스트하고 있던 폰은 iOS12 로 WiFi 정보를 받아오려면

Project File -> Capabilities 의 Access WiFi Information 을 on으로 변경해줘야한다.

 

변경해주었더니 잘 받아옴....

+ Recent posts