CloudKit Queries for logged out users

cloudkit logo
cloudkit offline
cloudkit team
cloudkit container
cloudkit vs icloud drive
apple cloudkit sample code
cloudkit ios 13

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 UserInfo=0x7c3498c0 {NSDebugDescription=connection to service named}

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

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

Providing User Access to CloudKit Data, Identify Containers and Record Types. To be sure that you're querying all the data stored by your app, cross-reference the list of containers your app has access to  When you detect that the current logged in user has changed, you probably want to remove all private data you have cached locally and fetch the data for the new user. Queries. Now that you’ve learned the basics of how to store data in CloudKit, it’s time to learn how to retrieve that data.

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)

OS X App Development with CloudKit and Swift, Second, you must add that role to the users to whom you wish to give those permissions. To create a new one, click on the + sign in the detail pane. “​Records of this type cannot be shown because there is no Query Index of Record ID field. Use each field's keys and values to give users an accessible report of the data your app stores in CloudKit. Note. If your app uses CloudKit subscriptions to maintain an on-device copy of user data, you can use that copy to generate the report rather than querying CloudKit.

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" UserInfo={NSDebugDescription=connection to service named}
Optional(Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named" UserInfo={NSDebugDescription=connection to service named})

CloudKit Tutorial: Getting Started, In this CloudKit tutorial, you'll learn how to add and query data in iCloud from your app, as well as how to As long as they are logged in, users can use your app seamlessly. Unfortunately, this sometimes gets out of sync. Record types use fields to define the various pieces of data each record contains. Under Schema, select Record Types and then New Type to add a new record type. Name your new record type Establishment, then press Enter. You’ll see a row of system fields, automatically created for every record type.

CloudKit JS Tutorial for iOS, setUpAuth() to check whether a user is signed in, and then it presents the appropriate sign-in/out button. You don't  CloudKit also provides a way to discover information about any user who might be friends of the currently logged on iCloud user by querying the whole Address Book. The CloudKit Process will pull in the user's Contact Book and use the email addresses to see if it can find other user's of the application that match those addresses.

CloudKit 101, These days you can also use Sign in with Apple, but that's a little bit more This does mean that if your user is out of space in their iCloud, you'll Performing queries is one of many things in CloudKit that uses operations. This sample demonstrates how any user can query records in the public database and a logged in user can query records in their private database. CloudKit on the web This web application provides executable sample code for the core API methods provided by the CloudKit JS JavaScript library.

Synchronizing data with CloudKit - Guilherme Rambo, You can use CloudKit just to get the user's unique identifier and use it as an With the introductory stuff out of the way, let's start coding. Just click "Add Record ID Query Index" and then the dashboard is going to show the to know if the user is logged in to iCloud on the current device to decide whether  Synchronizing data with CloudKit. There are many situations where we might have to know if the user is logged in to iCloud on the current device to decide whether a certain feature of the app