taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit 56c005892488e4d46745165c175ea5e669575485
parent 35d07ff6d9f3563f3f1617d7c7654d915f03067e
Author: Marc Stibane <marc@taler.net>
Date:   Tue,  7 May 2024 07:04:58 +0200

checkInternetConnection

Diffstat:
MTalerWallet1/Controllers/Controller.swift | 27++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/TalerWallet1/Controllers/Controller.swift b/TalerWallet1/Controllers/Controller.swift @@ -8,6 +8,7 @@ import SwiftUI import SymLog import os.log import CoreHaptics +import Network enum BackendState { case none @@ -36,6 +37,7 @@ class Controller: ObservableObject { @Published var backendState: BackendState = .none // only used for launch animation @Published var currencyTicker: Int = 0 // updates whenever a new currency is added + @Published var isConnected: Bool = true @AppStorage("useHaptics") var useHaptics: Bool = true // extension mustn't define this, so it must be here @AppStorage("playSoundsI") var playSoundsI: Int = 1 // extension mustn't define this, so it must be here @AppStorage("playSoundsB") var playSoundsB: Bool = false @@ -45,9 +47,31 @@ class Controller: ObservableObject { let player = AVQueuePlayer() let semaphore = AsyncSemaphore(value: 1) var currencyInfos: [CurrencyInfo] - var messageForSheet: String? = nil + private let monitor = NWPathMonitor() + + func checkInternetConnection() { + monitor.pathUpdateHandler = { path in + let status = switch path.status { + case .satisfied: "active" + case .unsatisfied: "inactive" + default: "unknown" + } + self.logger.log("Internet connection is \(status)") + DispatchQueue.main.async { + self.isConnected = (path.status == .satisfied) + } + } + self.logger.log("Start monitoring internet connection") + let queue = DispatchQueue(label: "InternetMonitor") + monitor.start(queue: queue) + } + func stopCheckingConnection() { + self.logger.log("Stop monitoring internet connection") + monitor.cancel() + } + init() { // for family in UIFont.familyNames { // print(family) @@ -58,6 +82,7 @@ class Controller: ObservableObject { backendState = .instantiated currencyTicker = 0 currencyInfos = [] +// checkInternetConnection() } // MARK: - func hasInfo(for currency: String) -> CurrencyInfo? {