Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jazzedge/c5ae82eeb469284f02dc4118fa9f927f to your computer and use it in GitHub Desktop.

Select an option

Save jazzedge/c5ae82eeb469284f02dc4118fa9f927f to your computer and use it in GitHub Desktop.
See: https://developer.apple.com/library/content/documentation/DataManagement/Conceptual/CloudKitQuickStart/CreatingaSchemabySavingRecords/CreatingaSchemabySavingRecords.html
Improve the user’s experience by verifying that the user is signed in to their iCloud account
before saving records. If the user is not signed in, present an alert instructing the user how
to enter their iCloud credentials and enable iCloud Drive.
Insert your code that saves records in the else clause below.
CKContainer.default().accountStatus(completionHandler: {(_ accountStatus: CKAccountStatus, _ error: Error?) -> Void in
if accountStatus == .noAccount {
var 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: "Okay", style: .cancel, handler: nil))
self.present(alert, animated: true) { _ in }
}
else {
// Insert your just-in-time schema code here
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment