Meshtastic-Apple/Meshtastic/Helpers/NetworkManager.swift
Garth Vander Houwen a990d7f2bd Lint
2023-08-26 23:17:30 -07:00

27 lines
603 B
Swift

//
// NetworkManager.swift
// Meshtastic
//
// Copyright(c) Garth Vander Houwen on 4/23/23.
//
import Foundation
import Network
class NetworkManager {
static let shared = NetworkManager()
// MARK: Public methods
func runIfNetwork(completion: @escaping () -> Void ) {
let pathMonitor = NWPathMonitor()
pathMonitor.pathUpdateHandler = {
guard $0.status == .satisfied else {
// No network available
print("Network Not available")
return pathMonitor.cancel()
}
pathMonitor.cancel()
completion()
}
pathMonitor.start(queue: DispatchQueue.global(qos: .background))
}
}