【Swift】在Swift中获取当前的wifi SSID

前端之家收集整理的这篇文章主要介绍了【Swift】在Swift中获取当前的wifi SSID前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
funcgetSSID()->String?{
letinterfaces:CFArray!=CNCopySupportedInterfaces()?.takeRetainedValue()
ifinterfaces==nil{returnnil}

letif0:UnsafePointer<Void>?=CFArrayGetValueAtIndex(interfaces,0)
ifif0==nil{returnnil}

letinterfaceName:CFStringRef=unsafeBitCast(if0!,CFStringRef.self)
letdictionary=CNCopyCurrentNetworkInfo(interfaceName)?.takeRetainedValue()asNSDictionary?
ifdictionary==nil{returnnil}

returndictionary?[kCNNetworkInfoKeySSIDasString]as?String
}

- -

项目中遇到了 那就随手记一下

原文链接:https://www.f2er.com/swift/327637.html

猜你在找的Swift相关文章