I want to receive notification in my iOS App when the iCloud account status changes, and hence I register via
NotificationCenter.default.addObserver(self, selector: #selector(iCloudAvailabilityChanged), name: Notification.Name.CKAccountChanged, object: nil)
And indeed, when I background my App, and flip the iCloud switch for the App in Settings, and then go back and foreground my App, I receive the notification right after applicationWillEnterForeground.
However, if I repeat this, so background my App for a second time, flip the switch, and then foreground my App again, the notification is NOT received. And also not if I do that a third, fourth, etc. time.
This behaviour happens to me not sometimes, but always, and I have tried on different devices and it is all the same.
I use iOS 13 and Swift 5.
Is this intended behaviour, or is it a bug, or am I doing something wrong? Thank you for any help!
As my comment above implies, I think you may be flipping the wrong switch. As I understand it, CKAccountChanged
is fired when you change one of two things:
Settings > iCloud Profile > iCloud > iCloud Drive
)I have not read anywhere that changing the iCloud availability for a specific app will fire CKAccountChanged
.