Make sure the network is reachable before trying to sync iCloud accounts.

This commit is contained in:
Maurice Parker 2020-04-11 16:45:31 -05:00
parent e6c5d2f199
commit 815cf31ab8
1 changed files with 8 additions and 0 deletions

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
import CloudKit import CloudKit
import SystemConfiguration
import os.log import os.log
import SyncDatabase import SyncDatabase
import RSCore import RSCore
@ -84,6 +85,13 @@ final class CloudKitAccountDelegate: AccountDelegate {
return 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) refreshAll(for: account, downloadFeeds: true, completion: completion)
} }