當我執行此代碼:查詢上的recordId導致「內部服務器錯誤」
CKDatabase *publicDatabase = [[CKContainer defaultContainer] publicCloudDatabase];
CKRecordID *recordID = [[CKRecordID alloc] initWithRecordName: @"95263874-C860-4190-A2BB-08B3E652B7AA"];
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"%K == %@", @"recordID", [[CKReference alloc] initWithRecordID: recordID action: CKReferenceActionNone]];
CKQuery *query = [[CKQuery alloc] initWithRecordType: @"Case" predicate: predicate];
[publicDatabase performQuery: query inZoneWithID: nil completionHandler: ^(NSArray *results, NSError *error) {
if (error) {
NSLog(@"Error = %@", error);
} else {
NSLog(@"Success");
}
}];
我得到這個錯誤:
<CKError 0x618000042670: "Server Rejected Request" (15/2000); server message = "Internal server error"; uuid = 122AB9AA-6949-442D-B9D7-736A5B7D2EE5; container ID = "iCloud.net.xxxxxxx">
但是,如果我改變謂語這樣:
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"PatientName = %@ ", @"Doe, John"];
檢索工作正常。我已經證實John Doe有我正在尋找的記錄名。我也嘗試在項目設置中切換iCloud「功能」。我花了幾個小時在這個問題上,並嘗試了很多變化。沒有用!
如果您知道記錄ID,您應該使用'CKFetchRecordsOperation'或至少使用'fetchRecordWithID:completionHandler:'獲得記錄。當你知道記錄ID時,要麼比使用'performQuery'要好。 – rmaddy
感謝您的建議,它的工作原理!如果您將此作爲答案,我會將其標記爲已接受。 – user1092808