mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
29 lines
573 B
Swift
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))
|
|
}
|
|
|
|
}
|