At WWDC this year, I was in the Network.framework session where the presenter had mentioned to switch from using SCNetworkReachability and use the capabilities provided by the new Network.framework. I'm in the process of doing so, but I'm unsure as to how to proceed with identifying the network interface that the update is for. In the SCNetworkReachability world, you call SCNetworkReachabilityGetFlags and check the value by ANDing with the interface you want. For the nw_path_t, do you call the nw_path_enumerate_interfaces function and try to query each nw_interface_t or do you make repeated calls to nw_path_uses_interface_type to determine the interface?
Sample:
- (void)setupNetworkMonitoring
{
dispatch_queue_attr_t attrs = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_UTILITY, DISPATCH_QUEUE_PRIORITY_DEFAULT);
self.monitorQueue = dispatch_queue_create("com.example.network-monitor", attrs);
// self.monitor = nw_path_monitor_create_with_type(nw_interface_type_wifi);
self.monitor = nw_path_monitor_create();
nw_path_monitor_set_queue(self.monitor, self.monitorQueue);
nw_path_monitor_set_update_handler(self.monitor, ^(nw_path_t _Nonnull path) {
nw_path_status_t status = nw_path_get_status(path);
// Determine the active interface, but how?
switch (status) {
case nw_path_status_invalid: {
// Network path is invalid
break;
}
case nw_path_status_satisfied: {
// Network is usable
break;
}
case nw_path_status_satisfiable: {
// Network may be usable
break;
}
case nw_path_status_unsatisfied: {
// Network is not usable
break;
}
}
});
nw_path_monitor_start(self.monitor);
}
Thanks for the further explanation.
The remaining task is to determine what interface the path is using, so do I A)
to get the interfaces or B) make multiple calls tonw_path_enumerate_interfaces
to determine what is in use?nw_path_uses_interface_type
Either will work but my preference is for B because it’s seems a lot more direct.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"