阅读背景:

iCloud错误读取资产或资产列表中的记录

来源:互联网 

Running Xcode 7.1.1 under El Capitan on an iPad with iOS 9.2.

在El Capitan下运行Xcode 7.1.1,在iPad上运行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?

它会因为下面的错误信息而崩溃……它甚至没有到达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
)}'.

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".

尝试了一个稍微简单的版本和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"])
            }
        }
    }
}
}

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)
}

1 个解决方案

#1


0  

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.

我发现解决办法;我不得不拼凑一个影子应用程序,让我可以通过API将图像上传到正确的数据库,并通过cloud kit仪表板。在使用API上载资产之后,上面的代码可以完美地工作。这个问题似乎是iCloudkit仪表板上的一个错误;也许是El Capitan特性、Xcode 7.1.1甚至IOS 9.2。


分享到: