Search code examples
iosobjective-ccloudkit

"Not Authenticated" (9/1002) error while accessing cloud kit public database


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];

Solution

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