Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ReachabilityListener): Remove background check code #149

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 7 additions & 27 deletions Sources/InfomaniakCore/Networking/ReachabilityListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
import Foundation
import Network

#if os(macOS)
import AppKit
#elseif os(iOS) || os(tvOS)
import UIKit
#elseif os(watchOS)
import WatchKit
#endif

@available(tvOS 12.0, watchOS 5.0, *)
public class ReachabilityListener {
public enum NetworkStatus {
case undefined
Expand Down Expand Up @@ -60,24 +51,14 @@ public class ReachabilityListener {
}

let newStatus = self.pathToStatus(path)
var inBackground = false
if !Bundle.main.isExtension {
DispatchQueue.main.sync {
#if os(macOS)
fatalError("unimplemented")
#elseif os(iOS) || os(tvOS)
inBackground = UIApplication.shared.applicationState == .background
#elseif os(watchOS)
inBackground = WKExtension.shared().applicationState == .background
#endif
}
guard newStatus != self.currentStatus else {
return
}
if newStatus != self.currentStatus && !inBackground {
self.currentStatus = newStatus
self.observersQueue.sync {
for closure in self.didChangeNetworkStatus.values {
closure(self.currentStatus)
}

self.currentStatus = newStatus
self.observersQueue.sync {
for closure in self.didChangeNetworkStatus.values {
closure(self.currentStatus)
}
}
}
Expand All @@ -99,7 +80,6 @@ public class ReachabilityListener {

// MARK: - Observation

@available(tvOS 12.0, watchOS 5.0, *)
public extension ReachabilityListener {
@discardableResult
func observeNetworkChange<T: AnyObject>(_ observer: T, using closure: @escaping (NetworkStatus) -> Void)
Expand Down