3
votes

I have integrated cloudkit framework in one of my iOS app and is working fine in iOS 8 and 9 but not in iOS 10. It fails to fetch the records from public database without active iCloud account. Able to fetch the records in iOS 8 and 9 if user restricted iCloud drive for the app also but it fails in iOS 10, getting error like

CKError 0x170249090: "Not Authenticated" (9/1002); "No backing account, so not returning an auth token."

It is not working for both development and production cloudkit environments in iOS devices. I have tested the app with AdHoc build pointing to production.

Below is my code

CKQuery *query = [[CKQuery alloc] initWithRecordType:@"RecordSettings" predicate:[NSPredicate predicateWithFormat:@"TRUEPREDICATE"]];

CKQueryOperation *queryOperation = [[CKQueryOperation alloc] initWithQuery:query];
queryOperation.queuePriority = NSOperationQueuePriorityVeryHigh;
queryOperation.recordFetchedBlock = ^(CKRecord *record) {
              if(record != nil) {
            }
};
queryOperation.queryCompletionBlock = ^(CKQueryCursor * __nullable cursor, NSError * __nullable operationError) {

                    NSLog(@"iCloud error: %@", operationError.description);
};
[[[CKContainer defaultContainer] publicCloudDatabase] addOperation:queryOperation];
3
Any luck with this? - Rishabh Tayal
still not able to figure it out. are you facing same issue as well? - Madhu

3 Answers

4
votes

You need to log in using your iCloud account on simulator or device. It worked for me.

The answer is in the section Enter iCloud Credentials Before Running Your App:

In development, when you run your app through Xcode on a simulator or a device, you need to enter iCloud credentials to read records in the public database. In production, the default permissions allow non-authenticated users to read records in the public database but do not allow them to write records.

0
votes

I am having the same issue. Everything worked great until iOS10. The only thing so far that I have found to fix this is for the user to have iCloud Drive enabled on their device to fetch any record in a public container. I'm in the process of filing a bug report with Apple!

-3
votes

This issue exists from iOS 10.0 to 10.1.1 but it has been resolved in iOS 10.2.