Running Xcode 7.1.1 under El Capitan on an iPad with iOS 9.2.
Running this code against a very simple database ... with a database containing a record type defined as a string, a reference + an asset field.
-(void)slideLoader:(CKRecordID*)slideReference {
privateDB = [[CKContainer defaultContainer] privateCloudDatabase];
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"presentationReference == %@", slideReference];
CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Slides" predicate:predicate];
[privateDB performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error){
if(error) {
NSLog(@"Error: %@", error.localizedDescription);
}
if(results) {
for(CKRecord *record in results) {
NSString *blah = [NSString stringWithFormat:@"%@",record[@"Order"]];
CKRecordID *blahR = record.recordID;
[pickerNames addObject:blah];
[slidesReferenceID addObject:blahR];
}
}
}];
}
It crashes with this error message [below] ... and wait it doesn't even get to the for loop; it crashed before that line. Now if I go into the iCloud dashboard and delete the asset field, it works perfectly... so what am I missing here?
<NSXPCConnection: 0x1557293e0> connection to service named com.apple.cloudd: Warning: Exception caught during decoding of received message, dropping incoming message.
Exception: Exception while decoding argument 0 (#2 of invocation):
<NSInvocation: 0x1555672e0>
return value: {v} void
target: {@} 0x0
selector: {:} handleOperationCompletion:forOperationWithID:
argument 2: {@} 0x0
argument 3: {@} 0x0
Exception: value for key 'NS.keys' was of unexpected class 'CKRecordID'. Allowed classes are '{(
NSURL,
NSString,
NSDate,
NSData,
NSNumber,
NSDictionary,
NSError,
NSArray
)}'.
Tried a slightly more simplistic version with Swift 2.0; same error. Here is that code, included as a mixed objective C/Swift 2.0 build. The Swift file is called "iCloudMethods.swift".
import Foundation
import CloudKit
@objc class iCloudMethods: NSObject {
func slideLoader(slideReference: CKRecordID) {
let container = CKContainer.defaultContainer()
let privateDB = container.privateCloudDatabase
let predicate = NSPredicate(format: "presentationReference == %@", slideReference)
let query = CKQuery(recordType: "Slides", predicate: predicate)
privateDB.performQuery(query, inZoneWithID: nil) { (results, error) -> Void in
if error != nil {
print(error)
}
if((results) != nil) {
for result in results! {
print(result["Order"])
}
}
}
}
}
Called with the statements...
#import "projectName-Swift.h"
iCloudMethods *iCloudMethod = [[iCloudMethods alloc] init];
[iCloudMethod slideLoader:presentationReferenceID[row]];
Sadly still crashes, same error message when I add assets to the dashboard, works perfectly if I leave them empty? To be sure the record definition looks like this...
Even tried to do this with an basic query operation, still fails.
func slideLoaderV2(slideReference: CKRecordID) {
let container = CKContainer.defaultContainer()
let privateDB = container.privateCloudDatabase
let predicate = NSPredicate(format: "presentationReference == %@", slideReference)
let query = CKQuery(recordType: "Slides", predicate: predicate)
let operation = CKQueryOperation(query: query)
operation.recordFetchedBlock = { (record) in
print(record["Order"])
}
operation.queryCompletionBlock = { [unowned self] (cursor, error) in
dispatch_async(dispatch_get_main_queue()) {
if error == nil {
print("ok")
} else {
print(error!.localizedDescription)
}
}
}
_ = privateDB.addOperation(operation)
}
OK,
I found the fix; I had to cobble together a shadow app that lets me upload images via the API to the right database and via the cloud kit dashboard. Having uploaded an Asset using the API, the code above works perfectly. The issue it would appear to be is a BUG in the iCloudkit DASHBOARD; perhaps its an El Capitan feature or Xcode 7.1.1 or even IOS 9.2.