Search code examples
iosswiftcloudkit

CKContainer fetchUserRecordIDWithCompletionHandler returns nil CKRecordID when iCloud Drive is disabled


Whenever I try to call CKContainer's fetchUserRecordIDWithCompletionHandler function I am unable to get a CKRecordID when iCloud Drive is disabled on the device's iCloud settings. The error returned is same one I would get as if the device had no linked iCloud account.

I am calling:

CKContainer.defaultContainer().fetchUserRecordIDWithCompletionHandler { (recordId, error) {
   //recordId is nil iff iCloud Drive is off
}

The error I am getting is:

<CKError 0x125647120: "Not Authenticated" (9/1002); "CloudKit access was denied by user settings"; Retry after 3.0 seconds>

If I switch iCloud Drive on everything works as normal. Is this behaviour per design or did I miss something?


Solution

  • It's working as designed. iCloud Drive is a requirement to use CloudKit. This is documented in the CloudKit Quick Start.

    Look under the Enter iCloud Credentials Before Running Your App section.