Determine if private database is available

Other topics

Remarks:

Account status returned can be: couldNotDetermine, available, restricted or noAccount.

The status can change while the app is running, use the NSUbiquityIdentityDidChangeNotification to detect account changes and call this method again to retrieve the status for the new account.

accountStatusWithCompletionHandler

CKContainer.defaultContainer().accountStatusWithCompletionHandler { accountStatus, error in
        if accountStatus == .NoAccount {
            let alert = UIAlertController(title: "Sign in to iCloud", message: "Sign in to your iCloud account to write records. On the Home screen, launch Settings, tap iCloud, and enter your Apple ID. Turn iCloud Drive on. If you don't have an iCloud account, tap Create a new Apple ID.", preferredStyle: .Alert)
            alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
            self.presentViewController(alert, animated: true, completion: nil)
        } else {
            // User has access to private database here...
        }
    }

Parameters:

ParameterDetails
completionHandlerA block that has no return value and takes the following parameters:
accountStatusThe status of the current user’s iCloud account.
errorAn error object or nil if the status is determined successfully. Use the information in the error object to determine whether the problem has a workaround.

Contributors

Topic Id: 5582

Example Ids: 19815

This site is not affiliated with any of the contributors.