Meshtastic-Apple/Meshtastic/Helpers/NetworkManager.swift
2023-04-25 17:56:57 -07:00

29 lines
573 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 ()->() ) {
let pathMonitor = NWPathMonitor()
pathMonitor.pathUpdateHandler = {
guard $0.status == .satisfied else {
// No network available
return pathMonitor.cancel()
}
pathMonitor.cancel()
completion()
}
pathMonitor.start(queue: DispatchQueue.global(qos: .background))
}
}