Created
January 12, 2019 22:24
-
-
Save dkw5877/b3a6e0bc8f279bdcb5a373d61494d84b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let monitor = NWPathMonitor() | |
/* closure called when path changes */ | |
let pathUpdateHandler = {(path:NWPath) in | |
let availableInterfaces = path.availableInterfaces | |
if !availableInterfaces.isEmpty { | |
//e.g. [ipsec4, en0, pdp_ip0] | |
let list = availableInterfaces.map { $0.debugDescription }.joined(separator: "\n") | |
} | |
var status = "undetermined" | |
switch path.status { | |
case .requiresConnection: | |
status = "requires connection" | |
case .satisfied: | |
status = "satisfied" | |
case .unsatisfied: | |
status = "unsatisfied" | |
} | |
} | |
/* set the closure */ | |
monitor.pathUpdateHandler = pathUpdateHandler | |
/* create the queue */ | |
let queue = DispatchQueue.init(label: "monitor queue", qos: .userInitiated) | |
/* start monitoring for changes */ | |
monitor.start(queue: queue) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment