From 0c2a7b82258be66d38400f7fefce5b515b36123e Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Tue, 18 Apr 2023 08:38:20 +0200 Subject: [PATCH] fix: NWPathMonitor must be recreated --- Mail/Utils/NetworkMonitor.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Mail/Utils/NetworkMonitor.swift b/Mail/Utils/NetworkMonitor.swift index 6b590c73c..19ab73eaf 100644 --- a/Mail/Utils/NetworkMonitor.swift +++ b/Mail/Utils/NetworkMonitor.swift @@ -23,12 +23,15 @@ class NetworkMonitor: ObservableObject { @Published var isConnected = true @Published var isCellular = false - private let monitor = NWPathMonitor() + private var monitor: NWPathMonitor? private let queue = DispatchQueue.global() public func start() { - monitor.start(queue: queue) - monitor.pathUpdateHandler = { [weak self] path in + if monitor == nil { + monitor = NWPathMonitor() + monitor?.start(queue: queue) + } + monitor?.pathUpdateHandler = { [weak self] path in DispatchQueue.main.async { self?.isConnected = path.status == .satisfied self?.isCellular = path.usesInterfaceType(.cellular) @@ -37,6 +40,7 @@ class NetworkMonitor: ObservableObject { } public func stop() { - monitor.cancel() + monitor?.cancel() + monitor = nil } }