Internet connectivity: NWPathMonitor

Ramesh Chavan
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();

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Ramesh Chavan
Ramesh Chavan

Written by Ramesh Chavan

Like to work on iOS, Android, UIPath and Graph DB

No responses yet

Write a response