我有某种CloudKit索引问题。当我使用CKModifyRecordsOperation将记录保存到iCloud时,modifyRecordsCompletionBlock不会返回任何错误。当我使用NSPredicate(值:true)或仪表板查询这些记录时,大多数情况下它会错过一两条记录。
所以说我上传5条记录(没有错误),等待一段时间(约15秒)以确保索引更新,然后查询它们(通过仪表板或应用程序的CKQueryOperation)。大多数时候它会显示4条记录5.再次,没有错误。记录位于customZone中的privateDB中。
这有点奇怪:我总是能够通过在“Fetch”菜单下的Dashboard(开发)中手动输入recordNames来获取查询未返回的记录。所以它存储它们,只是不查询。 当我在信息中心中删除索引并重新分配时,信息中心查询将开始返回所有结果(以前也省略了记录),但在上传几次后,将再次从查询中丢失。
这是我的CKModifyRecordsOperation:
let operation = CKModifyRecordsOperation(recordsToSave: records, recordIDsToDelete: [])
operation.modifyRecordsCompletionBlock =
{ [weak self] savedRecords, deletedRecordIDs, error in
guard error == nil else { // no errors here ... }
...
//for each item uploaded to iCloud, mark as synced
if let savedRecords = savedRecords{ // all attempted to save records are here
PendingCloudOperations.shared.markAsUploaded(
savedRecords.map{ $0.recordID.recordName })
}
completion(...)
}
operation.savePolicy = .changedKeys // tried .allKeys too
operation.qualityOfService = .userInitiated
self.privateDB.add(operation)
我尝试了记录字段(最初的日期,资产和参考),试图查看是否有任何字段出现问题。但即使我删除所有字段(创建没有额外字段的记录,只是系统元),问题仍然存在。我没有包含CKQueryOperation代码,因为Dashboard的行为与应用程序相同。
有什么想法吗?
编辑: 以下是我的提取功能:
var receipts:[FS_Receipt] = []
let query = CKQuery(recordType: myRecordType, predicate: NSPredicate(value: true))
let operation = CKQueryOperation(query: query)
//completion block
operation.queryCompletionBlock = { [weak self] cursor, error in
guard error == nil else {
// doesn't have any errors here
}
completion(...)
}
operation.recordFetchedBlock = { record in
// doesn't return all records here most of the time.
}
operation.qualityOfService = .userInitiated // without this, 'no internet' will NOT return error
operation.resultsLimit = 5000
operation.zoneID = customZoneID
self.privateDB.add(operation)
}