Search code examples
ios13cloudkit

CKAccountChanged notification is only received once


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!


Solution

  • 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:

    1. Sign in/out of iCloud on the device.
    2. Turn iCloud Drive on/off (in Settings > iCloud Profile > iCloud > iCloud Drive)

    I have not read anywhere that changing the iCloud availability for a specific app will fire CKAccountChanged.