diff --git a/WireNetwork/Sources/WireNetwork/Network/NetworkStack/NetworkReachability.swift b/WireNetwork/Sources/WireNetwork/Network/NetworkStack/NetworkReachability.swift new file mode 100644 index 00000000000..c9cc062211d --- /dev/null +++ b/WireNetwork/Sources/WireNetwork/Network/NetworkStack/NetworkReachability.swift @@ -0,0 +1,44 @@ +// +// Wire +// Copyright (C) 2025 Wire Swiss GmbH +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see http://www.gnu.org/licenses/. +// + +@preconcurrency import Combine +import Foundation +import Network + +public final class NetworkReachability: Sendable { + + private let monitor = NWPathMonitor() + private let isReachableSubject = CurrentValueSubject(true) + private let queue = DispatchQueue(label: "NetworkReachabilityQueue") + + public var isReachablePublisher: AnyPublisher { + isReachableSubject.eraseToAnyPublisher() + } + + public init() { + monitor.pathUpdateHandler = { [weak self] path in + self?.isReachableSubject.send(path.status == .satisfied) + } + monitor.start(queue: queue) + } + + deinit { + monitor.cancel() + } + +} diff --git a/wire-ios-sync-engine/Source/UserSession/ZMUserSession/ZMUserSession.swift b/wire-ios-sync-engine/Source/UserSession/ZMUserSession/ZMUserSession.swift index 15e3d2b69ad..2cecfaf7fe1 100644 --- a/wire-ios-sync-engine/Source/UserSession/ZMUserSession/ZMUserSession.swift +++ b/wire-ios-sync-engine/Source/UserSession/ZMUserSession/ZMUserSession.swift @@ -404,6 +404,9 @@ public final class ZMUserSession: NSObject { private let userSessionComponent: UserSessionComponent public private(set) var clientSessionComponent: ClientSessionComponent? + private let networkReachability = NetworkReachability() + private var isNetworkReachableCancellable: AnyCancellable? + // MARK: - Initialize init( @@ -489,6 +492,12 @@ public final class ZMUserSession: NSObject { super.init() + if DeveloperFlag.multibackend.isOn { + self.isNetworkReachableCancellable = networkReachability.isReachablePublisher + .sink { [weak self] isReachable in + isReachable ? self?.didReceiveData() : self?.didGoOffline() + } + } } func trackAppOpenAnalyticEventWhenAppBecomesActive() { @@ -698,7 +707,10 @@ public final class ZMUserSession: NSObject { private func configureTransportSession() { transportSession.pushChannel.clientID = selfUserClient?.remoteIdentifier - transportSession.setNetworkStateDelegate(self) + // When multibackend is on. we use another reachability. + if !DeveloperFlag.multibackend.isOn { + transportSession.setNetworkStateDelegate(self) + } transportSession.setAccessTokenRenewalFailureHandler { [weak self] response in self?.transportSessionAccessTokenDidFail(response: response) } diff --git a/wire-ios/Wire-iOS Share Extension/Generated/Strings+Generated.swift b/wire-ios/Wire-iOS Share Extension/Generated/Strings+Generated.swift index a519c562325..0df4b87a636 100644 --- a/wire-ios/Wire-iOS Share Extension/Generated/Strings+Generated.swift +++ b/wire-ios/Wire-iOS Share Extension/Generated/Strings+Generated.swift @@ -49,8 +49,8 @@ internal enum L10n { internal enum UpdateRequired { /// Your Wire server needs to be updated. Please notify your system administrator. internal static let obsoleteBackend = L10n.tr("Localizable", "share_extension.error.update_required.obsolete_backend", fallback: "Your Wire server needs to be updated. Please notify your system administrator.") - /// You are missing out on new features. Get the latest version of Wire to continue using the app with this account. - internal static let obsoleteClient = L10n.tr("Localizable", "share_extension.error.update_required.obsolete_client", fallback: "You are missing out on new features. Get the latest version of Wire to continue using the app with this account.") + /// You are missing out on new features. Get the latest version of Wire to continue using the app with this account. + internal static let obsoleteClient = L10n.tr("Localizable", "share_extension.error.update_required.obsolete_client", fallback: "You are missing out on new features. Get the latest version of Wire to continue using the app with this account.") /// Update required internal static let title = L10n.tr("Localizable", "share_extension.error.update_required.title", fallback: "Update required") }