zoukankan      html  css  js  c++  java
  • Swift3 获取当前连接WIFI名称

    1、导入库

    import SystemConfiguration
    import SystemConfiguration.CaptiveNetwork

    2、方法

     /// 获取wifi名称
        ///
        /// - Returns: <#return value description#>
        func getUsedSSID() -> String {
            let interfaces = CNCopySupportedInterfaces()
            var ssid = ""
            if interfaces != nil {
                let interfacesArray = CFBridgingRetain(interfaces) as! Array<AnyObject>
                if interfacesArray.count > 0 {
                    let interfaceName = interfacesArray[0] as! CFString
                    let ussafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
                    if (ussafeInterfaceData != nil) {
                        let interfaceData = ussafeInterfaceData as! Dictionary<String, Any>
                        ssid = interfaceData["SSID"]! as! String
                    }
                }
            }
            return ssid
        }

    SSID就是连接wifi的名称,直接使用即可,如果没读到,返回的空""

    enjoy~

  • 相关阅读:
    springMvc
    计算机网络
    Mybatis 总结
    Spring 面试总结
    Java IO 流
    自定义类加载器
    缓存一致性协议
    dfs、bfs序
    7.26
    Trick
  • 原文地址:https://www.cnblogs.com/yajunLi/p/6693024.html
Copyright © 2011-2022 走看看