Use new Reachability.internetIsReachable.

This commit is contained in:
Brent Simmons 2024-04-06 19:02:11 -07:00
parent 46645f700a
commit 3b59ffc446
3 changed files with 18 additions and 38 deletions

View File

@ -221,18 +221,9 @@ import Secrets
}
}
private func internetIsReachable() -> Bool {
guard let reachability = try? Reachability(hostname: "apple.com"), reachability.connection != .unavailable else {
return false
}
return true
}
public func refreshAll(errorHandler: ((Error) -> Void)? = nil) async {
guard internetIsReachable() else {
guard Reachability.internetIsReachable else {
return
}

View File

@ -90,13 +90,7 @@ enum CloudKitAccountDelegateError: LocalizedError {
func refreshAll(for account: Account) async throws {
guard refreshProgress.isComplete else {
return
}
let reachability = SCNetworkReachabilityCreateWithName(nil, "apple.com")
var flags = SCNetworkReachabilityFlags()
guard SCNetworkReachabilityGetFlags(reachability!, &flags), flags.contains(.reachable) else {
guard refreshProgress.isComplete, Reachability.internetIsReachable else {
return
}

View File

@ -23,8 +23,7 @@ struct CacheCleaner {
// If the image disk cache hasn't been flushed for 3 days and the network is available, delete it
if flushDate.addingTimeInterval(3600 * 24 * 3) < Date() {
if let reachability = try? Reachability(hostname: "apple.com") {
if reachability.connection != .unavailable {
if Reachability.internetIsReachable {
let tempDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
let faviconsFolderURL = tempDir.appendingPathComponent("Favicons")
@ -43,11 +42,7 @@ struct CacheCleaner {
}
AppDefaults.shared.lastImageCacheFlushDate = Date()
}
}
}
}
}