From d6aa5f23ba5e24c504462fd91e87b5f829749696 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 17 Jun 2021 19:05:39 -0500 Subject: [PATCH] Don't allow the creation of iCloud accounts if iCloud and iCloud Drive aren't enabled. Fixes #3106 --- .../AccountsAddCloudKitWindowController.swift | 13 +++++++++++++ iOS/Account/CloudKitAccountViewController.swift | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift b/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift index 5d0e3202f..388e7af20 100644 --- a/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift @@ -9,6 +9,14 @@ import Foundation import Account +enum AccountsAddCloudKitWindowControllerError: LocalizedError { + case iCloudDriveMissing + + var errorDescription: String? { + return NSLocalizedString("Unable to add iCloud Account. Please make sure you have iCloud and iCloud enabled in System Preferences.", comment: "Unable to add iCloud Account.") + } +} + class AccountsAddCloudKitWindowController: NSWindowController { private weak var hostWindow: NSWindow? @@ -35,6 +43,11 @@ class AccountsAddCloudKitWindowController: NSWindowController { } @IBAction func create(_ sender: Any) { + guard FileManager.default.ubiquityIdentityToken != nil else { + NSApplication.shared.presentError(AccountsAddCloudKitWindowControllerError.iCloudDriveMissing) + return + } + let _ = AccountManager.shared.createAccount(type: .cloudKit) hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK) } diff --git a/iOS/Account/CloudKitAccountViewController.swift b/iOS/Account/CloudKitAccountViewController.swift index 1cf5b3ad6..af0e85ae8 100644 --- a/iOS/Account/CloudKitAccountViewController.swift +++ b/iOS/Account/CloudKitAccountViewController.swift @@ -9,6 +9,14 @@ import UIKit import Account +enum CloudKitAccountViewControllerError: LocalizedError { + case iCloudDriveMissing + + var errorDescription: String? { + return NSLocalizedString("Unable to add iCloud Account. Please make sure you have iCloud and iCloud enabled in System Preferences.", comment: "Unable to add iCloud Account.") + } +} + class CloudKitAccountViewController: UITableViewController { weak var delegate: AddAccountDismissDelegate? @@ -31,6 +39,11 @@ class CloudKitAccountViewController: UITableViewController { } @IBAction func add(_ sender: Any) { + guard FileManager.default.ubiquityIdentityToken != nil else { + presentError(CloudKitAccountViewControllerError.iCloudDriveMissing) + return + } + let _ = AccountManager.shared.createAccount(type: .cloudKit) dismiss(animated: true, completion: nil) delegate?.dismiss()