16
votes

In the documents it says that CloudKit public databases will be available to read even if the user did not login with a proper iCloud account. However, I cannot fetch anything from my cloud database if i didn't connect my iOS simulator or device to iCloud. When i activate my iCloud account I am able to fetch data from my public database. If anyone who has an answer or same problem with me could answer that would be great. Thanks.

CKDatabase *publicDatabase = [[CKContainer containerWithIdentifier:@"mycontainer"] publicCloudDatabase];
CKRecordID *recordID = [[CKRecordID alloc] initWithRecordName:@"idofmyrecord"] ;

[publicDatabase fetchRecordWithID:recordID completionHandler:^(CKRecord *fetchedRecord, NSError *error) {
    if(!error){
        NSLog(@"****Success***** %@",fetchedRecord[@"field1"]);

    }else{
        NSLog(@"****Failed***** %@",fetchedRecord[@"field2"]);

    }
}];
2
is container connection operatonal? I usually use [CKContainer defaultContainer] - János
I am using a different container because my data is stored at a different container. How can I change connection settings to allow access without iCloud account or can it be done? Thanks for help. - Ersin Sezgin
It should not be a problem to perform fetchRecordWithID method without be logged in, what does containerWithIdentifier return? - János
<CKContainer: containerInTheMemory; containerID=<CKContainerID: myContainerId; containerIdentifier=mycontainer, containerEnvironment="Sandbox">> this is what i get as a results of po [CKContainer containerWithIdentifier:@"mycontainer"] - Ersin Sezgin
I would check container's accountStatusWithCompletionHandler method to see its status. - János

2 Answers

10
votes

The public database is only readable with no login in the production environment, not in the development environment.

Apple's documentation says:

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.

See CloudKit Quick Start.

3
votes

I think the documentation is incorrect or this is a bug in Apple's code. You should file a radar at https://developer.apple.com/bug-reporting/