在iOS 9.2的iPad上运行El Capitan下的Xcode 7.1.1。
针对一个非常简单的数据库运行此代码...使用包含定义为字符串的记录类型的数据库,引用+资产字段。
-(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];
}
}
}];
}
它崩溃了这个错误消息[下面] ...等待它甚至没有进入for循环;它在那条线之前坠毁了。现在,如果我进入iCloud仪表板并删除资产字段,它就能完美运行......所以我在这里缺少什么?
<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
)}'.
使用Swift 2.0尝试稍微简单化的版本;同样的错误。这是代码,作为混合目标C / Swift 2.0构建。 Swift文件名为“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"])
}
}
}
}
}
调用陈述......
#import "projectName-Swift.h"
iCloudMethods *iCloudMethod = [[iCloudMethods alloc] init];
[iCloudMethod slideLoader:presentationReferenceID[row]];
当我将资源添加到仪表板时,遗憾地仍然崩溃,同样的错误信息,如果我将它们留空,效果会很好吗?为了确保记录定义看起来像这样......
即使尝试使用基本查询操作执行此操作,仍然会失败。
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)
}
答案 0 :(得分:0)
行,
我找到了修复;我不得不拼凑一个影子应用程序,让我通过API将图像上传到正确的数据库,并通过云套件仪表板。使用API上传资产后,上面的代码运行完美。看起来似乎是iCloudkit DASHBOARD中的BUG;也许它是El Capitan功能或Xcode 7.1.1甚至是IOS 9.2。