“Not Authenticated” (9/1002) error while accessing cloud kit public database in iOS 10

Hi,


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


Thanks,

Replies

Same problem here...

I'm also having some problems with CloudKit and the publicDatabase's defaultContainer on iOS 10... mine is a different problem, but I wonder if maybe these bugs are related. Here is my issue: https://forums.developer.apple.com/thread/62699


It seems that nobody except those of us with problems even actually reads this sub-forum. Nobody from Apple cares about us down in the CloudKit dungeon here. Sigh. (Real developers have their own servers.)


Somehow my gut tells me this issue has to do with corrupt provisioning profile and/or entitlements, or something weird in XCode project files not properly migrating and then not transferring the entitlements into the app properly. Makes me think I should just start a new XCode project entirely then move all my files into it from the old one; only problem is I have a very complicated and huge project with lots of sub-projects and custom build arguments so this would be a big-time PITA. Sigh.

I think this might be a bug because if you go to your phone and icloud settings and retype your iCloud password, it'll work at times.


If it is changed behavior, that sorta ***** because I used it a lot within my app and it worked during most of the betas (broke with the GM seed, I believe)

From Apple Developer Technical Support:


This sounds like a server side issue with CloudKit, and not with your app’s code, if it works in iOS 9 and not iOS 10.


I submitted a bug report. I hope they will fix this soon.

Hi everyone,


I have an application on AppStore, which use CloudKit to fetch public data. Perfect in all iOS9 or below devices, also the developing version of iOS10 devices. After iOS10 released some of my users claimed that they can't fetch public data. I checked all my code, cloned a new project with the same Bundle Identifier, or cleaned up my production database and deployed again from the development database, but nothing worked.


It brothered me for a whole week, but now I find one solution rather than wait for Apple. I think the public container related to Bundle Identifier is already broken and ban the request of iOS10 devices. Fellow the steps below may help:

THESE STEPS WON'T KEEP THE EXISTED DATA IN THE BROKEN CONTAINER

1. Change the Bundle Identifier in General of your application target and turn iCloud capabilities on and off to create new iCloud container.

2. Change back the original Bundle Idenitifer and turn iCloud capabilites on and off.

3. Change your code from 'CKContainer.defaultContainer' to 'CKContainer.containerWithIdenifier:<Your new iCloud container>'.


P.S. As I can only use a new container to solve, I suggest that Apple may add buttons in CloudKit webpage, allowing developer to reset the whole container using the same Bundle Identifier.

Please let me know if they fix it. Thanks!

Hi All,


I too had this issue however it was affecting only certain users and only on certain devices. From what I can tell, users that upgraded to iOS10 need to be signed into iCloud with iCloud Drive enabled even to access data in a Public Container. I had the affected users turn on their iCloud Drive and that seemed to fix the issue. Bug report to follow.

try simulator sign in icloud account then its worked

I use this method to solve

Same here. I have experienced a weird situation testing it on two iPhones:

  • iPhone 6 with my application installed firstly on iOS9, then upgraded to iOS10, iCloud account with iCloud Drive used, but with 2-factor authentication
  • iPhone 6S with fresh iOS10 installed and my application installed there for the first time, other iCloud account with iCloud Drive used, but without 2-factor authenticaton

After logging out from iCloud and logging in on my Iphone6, the default cointainer started to be available again.


My conlusion is that it was caused either by the upgrade from iOS9 to iOS10 or maybe enabling 2-factor authentication without logging out, cased some issues...

iOS 10.0 ~ 10.1.1 required iCloud Drive enabled to access public database.

It seems like a bug and fixed in iOS 10.2 beta.