CloudKit CKQuery has stopped working

OK, I found the issue, but since I have written all of this, I will still post it in case others have the same problem.



I have been developing a Mac app and an iPhone app, synchronizing Cored Data databases. Until this weekend everything was working well. Every time something didn't work, I could debug it and figure out the issue. However, it seems like now all of my queries never complete.


Here is one section of code which used to work but now doesn't.


CKRecordID *itemRecordID = [[CKRecordID alloc] initWithRecordName:itemRecord.recordKey];


CKReference *itemRecordTypeReference = [[CKReference alloc] initWithRecordID:itemRecordID action:CKReferenceActionNone];


NSPredicate *predicate = [NSPredicate predicateWithFormat:@"itemRecord == %@", itemRecordTypeReference];



CKQuery *query = [[CKQuery alloc] initWithRecordType:@"AttributeValueRecordType" predicate:predicate];


[self.bubingaDatabase performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error) {

if(error) {

}

else{

}


I have appropriate code after the query to handle errors and to process the results.


However, the if(error) line never gets hit. I share this object, CloudManger.h and .m in both the Mac app and the iPhone app, and I swear it was working. Now the queries never return at all. I am stuck

Replies

Oh, I forgot to include what I found.

My database object, the CKDatabase, is nil!!


So now, I'm tracking out why.

Ah, here's this issue.


(lldb) po __sharedManager.bubingaContainer

<CKContainer: 0x174164bc0; containerID=<CKContainerID: 0x174028b00; containerIdentifier=iCloud.com.rschluet.bubinga, containerEnvironment="Sandbox">>


I changed the environment to Production on the dashboard. I wonder how to do the same in the app. Time for some research.

Changing the environment on the Dashboard doesn't have any impact on your application. That just controls what environment you're looking at in the Dashboard.


What environment your app is working with is controlled by the setting of the com.apple.developer.icloud-container-environment entitlement. Are you sure that you're initializing that self.bubingaDatabase property before trying to use it? Is that a strong property?