From 815cf31ab8d749afeaefa0cae54325e8498eb5c6 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 11 Apr 2020 16:45:31 -0500 Subject: [PATCH] Make sure the network is reachable before trying to sync iCloud accounts. --- Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift b/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift index ca7ce0c0c..a9ea780cb 100644 --- a/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift @@ -8,6 +8,7 @@ import Foundation import CloudKit +import SystemConfiguration import os.log import SyncDatabase import RSCore @@ -84,6 +85,13 @@ final class CloudKitAccountDelegate: AccountDelegate { return } + let reachability = SCNetworkReachabilityCreateWithName(nil, "apple.com") + var flags = SCNetworkReachabilityFlags() + guard SCNetworkReachabilityGetFlags(reachability!, &flags), flags.contains(.reachable) else { + completion(.success(())) + return + } + refreshAll(for: account, downloadFeeds: true, completion: completion) }