4
votes

So according to Apple's documentation, users not logged into iCloud are still allowed to read from public databases, but when querying a public database, I get the following error:

Error Domain=NSCocoaErrorDomain Code=4097 "The operation couldn’t be completed. (Cocoa error 4097.)" (connection to service named com.apple.cloudd) UserInfo=0x7c3498c0 {NSDebugDescription=connection to service named com.apple.cloudd}

Here's my code for reference:

let container = CKContainer.defaultContainer()
let database = container.publicCloudDatabase

let predicate = NSPredicate(value: true)
let episodeQuery = CKQuery(recordType: "Episode", predicate: predicate)
database.performQuery(episodeQuery, inZoneWithID: nil) {
    // Record handling goes here
}

Any thoughts, tips, or advice is certainly appreciated. Thanks so much

3

3 Answers

3
votes

Error 4097 is returned when your application can't talk to cloudd, the CloudKit daemon.

This could either be due to an issue with entitlements or a bug in cloudd. Check your syslog for more clues and look for crash logs from cloudd. If you have a crash log for cloudd please attach it to a new radar at bugreport.apple.com

0
votes

I had a similar issue - after checking the system log as suggested by @farktronix, after filtering by cloudd I saw:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unexpected expression: NSSelfExpression'

Turns out my query predicate was incorrect - in my subscription query, I was trying to use the predicate:

NSPredicate(format: "self = %@", someCKRecord)

whereas I should have been using

NSPredicate(format: "recordID = %@", someCKRecord.recordID)
0
votes

I have the similar issue if I send too many times requests to iCloud.

It happens for me when I'm trying to do CKModifyRecordsOperation and there are more than 100 recordsToSave. I tried about 3 consecutive times to do this operation. And then I got this error. Then every single CloudKit API has been denied. After few minutes later, every recovered.

2019-01-14 20:27:19.326912+1300 inkDiary[27136:5424371] [LogFacilityCK] Got a connection error for operation 95C747D64BEA5FAC: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.cloudd" UserInfo={NSDebugDescription=connection to service named com.apple.cloudd}
Optional(Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.cloudd" UserInfo={NSDebugDescription=connection to service named com.apple.cloudd})