diff --git a/LeCountdown/LeCountdownApp.swift b/LeCountdown/LeCountdownApp.swift index 3f60bf2..2d3d8c0 100644 --- a/LeCountdown/LeCountdownApp.swift +++ b/LeCountdown/LeCountdownApp.swift @@ -10,6 +10,7 @@ import CoreData import BackgroundTasks import AVFoundation import Combine +import CloudKit @main struct LeCountdownApp: App { @@ -79,6 +80,8 @@ struct LeCountdownApp: App { Logger.log("preferredLanguages = \(String(describing: Locale.preferredLanguages))") self._patch() + let containerAvailable = self.isICloudContainerAvailable() + Logger.log("isICloudContainerAvailable = \(containerAvailable)") // let voices = AVSpeechSynthesisVoice.speechVoices() // let grouped = Dictionary(grouping: voices, by: { $0.language }) @@ -115,7 +118,6 @@ struct LeCountdownApp: App { } - fileprivate func _patch() { let context = PersistenceController.shared.container.viewContext @@ -131,4 +133,37 @@ struct LeCountdownApp: App { } + func isICloudContainerAvailable() -> Bool { + print(#function) + CKContainer.default().accountStatus { (accountStatus, error) in + + if accountStatus == .available { + return + } + + /// + // Checking account availability + // Silently return if everything goes well, or do a second check 200ms after the first failure + // + + DispatchQueue.global().asyncAfter(deadline: .now() + 0.2) { + + guard error != nil, accountStatus != CKAccountStatus.available else {return} + + print("iCloud account is not available! Be sure you have signed in iCloud on this device!") + } + } + + + if FileManager.default.ubiquityIdentityToken != nil { + //print("User logged in") + return true + } + else { + //print("User is not logged in") + return false + } + + } + } diff --git a/LeCountdown/Views/ContentView.swift b/LeCountdown/Views/ContentView.swift index 9c92bb5..b64a9eb 100644 --- a/LeCountdown/Views/ContentView.swift +++ b/LeCountdown/Views/ContentView.swift @@ -170,8 +170,6 @@ struct MainToolbarView: ToolbarContent { @Binding var isEditing: Bool -// @State var type: TimerType? = nil - @State var showSettingsSheet: Bool = false @State var showStatsSheet: Bool = false @State var showAddSheet: Bool = false