I want to receive notifications when the iCloud account status changes.
I thus register for these notifications with:
NotificationCenter.default.addObserver(self,
selector: #selector(iCloudAvailabilityDidChange),
name: .CKAccountChanged,
object: nil)
and expect that iCloudAvailabilityDidChange
is called accordingly:
@objc func iCloudAvailabilityDidChange(_ notification: Notification) {
handleICloudAccountStatus()
}
To check these notifications, I set a breakpoint in iCloudAvailabilityDidChange
, and run the app under Xcode.
I then issue Home
, open the system setting app, and log into an iCloud account or log out of it.
I expected Xcode to hit the breakpoint, but this is not the case.
What could be wrong?
EDIT:
Maybe the problem is related to the following info in the docs to CKAccountChanged
that I do not understand:
The notification is sent by an instance of the CKContainer class. If there are no instances of the class, notifications are not sent.
What I do not understand is that CKContainer.default()
should always be defined.
Problem solved:
First, one has to access the container, e.g. by
let container = CKContainer.default()
This instantiates the container object that can send such notifications.
Second, to get the notification one has to run the app, tap the home button, open systems settings, log in or out to/from the iCloud account, and switch back to the app. Only then is the notification delivered.