美文网首页
iPhone 14 Pro Max 获取的网卡信息不包含en0

iPhone 14 Pro Max 获取的网卡信息不包含en0

作者: 广益散人 | 来源:发表于2022-12-21 17:25 被阅读0次
        func isWiFiOn() -> Bool {
          var address : String?
          var ifaddr : UnsafeMutablePointer<ifaddrs>? = nil
          guard  getifaddrs(&ifaddr) == 0 else {
            return true
          }
          defer {
            freeifaddrs(ifaddr)
          }
    
          var ptr = ifaddr
          while ptr != nil {
            defer { ptr = ptr?.pointee.ifa_next }
            let interface = ptr!.pointee
            let addrFamily = interface.ifa_addr.pointee.sa_family
            if addrFamily == UInt8(AF_INET) || addrFamily == UInt8(AF_INET6) {
    
              guard let interface_name:UnsafeMutablePointer<Int8> = (interface.ifa_name) else {
                  continue
              }
              let name: String = String(cString: interface_name)
              guard name == "en0" else {
                  continue
              }
    
              if (Int32(interface.ifa_flags) & IFF_UP) == IFF_UP {
                  return(true)
              }
              else {
                return(false)
              }
            }
          }
       return (false)
        }
    
    

    上述代码中在部分iPhone 14 pro Max 机型上获取到的interface_name没有“en0”,暂未定位到原因

    相关文章

      网友评论

          本文标题:iPhone 14 Pro Max 获取的网卡信息不包含en0

          本文链接:https://www.haomeiwen.com/subject/prpmqdtx.html