Hello Cloud Kit - Part 2
Episode
#259
|
10 minutes
| published on
March 9, 2017
| Uses iOS-10.2
Free Video
In order to use CloudKit to read or write private data (or to write in the public database) the user will have to be signed in to iCloud on their device. If they are not, they'll not have a great experience, and things won't work. In this episode we'll check the account status before trying to save a record in CloudKit. We'll also respond to the notification to know when the user's account status has changed so we can react accordingly.
This episode is part of a series: Hello CloudKit.
1. Hello Cloud Kit - Part 1 10 min |
2. Hello Cloud Kit - Part 2 10 min |
3. CloudKit Querying 12 min |
4. CloudKit References 7 min |
5. Fetching and Saving References 15 min |
6. Working with Images 15 min |
7. Fetching Paged Images 8 min |
8. CKRecord Upload Progress 6 min |
9. Isolating CloudKit from your Controllers 16 min |
10. Extracting CKRecordWrapper 7 min |
11. CloudKit Notes Manager 11 min |
12. CloudKit Notes Manager Continued 14 min |
Want more? Subscribers can view all 471 episodes. New episodes are released regularly.
Episode Links
Checking Account Status
func checkAccountStatus() {
print("Checking account status:")
let container = CKContainer.default()
container.accountStatus { (accountStatus, error) in
print("Account status: \(accountStatus.rawValue)")
switch accountStatus {
case .available:
self.insertFirstRestaurant(container: container)
case .noAccount:
self.promptForICloud()
case .couldNotDetermine:
if let e = error {
print("Error checking account status: \(e)")
}
case .restricted:
print("restricted")
}
}
}
Handling Account Status Changes
NotificationCenter.default.addObserver(forName: .CKAccountChanged,
object: nil,
queue: nil) { [weak self] (note) in
print("Identity changed.")
self?.checkAccountStatus()
}