Created
January 17, 2023 12:10
-
-
Save dinotrnka/f845ce63b89eab7d5bbfeb0be9500d21 to your computer and use it in GitHub Desktop.
This file contains 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
import Foundation | |
import Network | |
class NetworkMonitor { | |
static let shared: NetworkMonitor = NetworkMonitor() | |
let monitor = NWPathMonitor() | |
private var status: NWPath.Status = .requiresConnection | |
var isReachable: Bool { status == .satisfied } | |
func startMonitoring() { | |
monitor.pathUpdateHandler = { path in | |
self.status = path.status | |
} | |
let queue = DispatchQueue(label: "Monitor") | |
monitor.start(queue: queue) | |
} | |
func stopMonitoring() { | |
monitor.cancel() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment