Internet connectivity: NWPathMonitor
Oct 3, 2022
Apple’s Network framework provides a number of useful classes for working with network data, including one specifically designed to monitor network accessibility: NWPathMonitor
. If you ever used Apple’s older Reachability system, NWPathMonitor
replaces it fully.
import Networkclass CheckNetwork {let monitor = NWPathMonitor()init(){monitor.pathUpdateHandler = { path inif path.status == .satisfied {print("We're Connected");}else{print("No Connection.")}print(path.isExpensive)}let queue = DispatchQueue(label: "Monitor")monitor.start(queue: queue);}@objc func closeNwConCheck(){monitor.cancel();print("closeNwConCheck")}}let nw = CheckNetwork();