iOS ethernet detection

Hello,


is there any way to detect if current connectivity is using wired ethernet on iOS ?


Davie Scrève

Answered by DTS Engineer in 378877022

It’s hard to answer this without a more concrete definition of what you mean by “current connectivity”. I suspect you’re asking about the default route, in which case the best way forward is

NWPathMonitor
. For example:
let monitor = NWPathMonitor()

func startPathMonitor() {
    self.monitor.pathUpdateHandler = { path in
        print(path.usesInterfaceType(.wiredEthernet))
        print("--")
    }
    self.monitor.start(queue: .main)
}

Note that I’m using

usesInterfaceType(_:)
here, because the default route might be a VPN and you need to test what interface that’s running over.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Accepted Answer

It’s hard to answer this without a more concrete definition of what you mean by “current connectivity”. I suspect you’re asking about the default route, in which case the best way forward is

NWPathMonitor
. For example:
let monitor = NWPathMonitor()

func startPathMonitor() {
    self.monitor.pathUpdateHandler = { path in
        print(path.usesInterfaceType(.wiredEthernet))
        print("--")
    }
    self.monitor.start(queue: .main)
}

Note that I’m using

usesInterfaceType(_:)
here, because the default route might be a VPN and you need to test what interface that’s running over.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thats exactly the kind of thing I'm looking for also, but for Objective C. Does an equivalent method exist for Objective C that you could point me towards?

iOS ethernet detection
 
 
Q