You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
672 B
28 lines
672 B
//
|
|
// NetworkMonitor.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 16/04/2024.
|
|
//
|
|
|
|
import Foundation
|
|
import Network
|
|
|
|
class NetworkMonitor: ObservableObject {
|
|
let monitor = NWPathMonitor()
|
|
let queue = DispatchQueue(label: "Monitor")
|
|
@Published private(set) var connected: Bool = false
|
|
|
|
func checkConnection() {
|
|
monitor.pathUpdateHandler = { path in
|
|
DispatchQueue.main.async {
|
|
if path.status == .satisfied {
|
|
self.connected = true
|
|
} else {
|
|
self.connected = false
|
|
}
|
|
}
|
|
}
|
|
monitor.start(queue: queue)
|
|
}
|
|
}
|
|
|