[英]Querying shared records in a ckzone in the private database returns nothing
Swift 4.2 iOS 11.x Swift 4.2 iOS 11.x
I must have missed something cause this surely should work. 我一定错过了一些东西,因为这肯定可以工作。 I got this code that queries the private database in a custom zone. 我得到了在自定义区域中查询私有数据库的代码。 It returns nothing despite the fact that I have records there. 尽管我在那里有记录,但它什么也没返回。 I added indexes to everything! 我为所有内容添加了索引! I also changed the roles in permissions so that any authenticated user could read records. 我还更改了权限中的角色,以便任何经过身份验证的用户都可以读取记录。
public func cleanUpImages(zone2U:String) {
var records2Delete:[CKRecord.ID] = []
let zone2D = CKRecordZone(zoneName: zone2U)
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: remoteRecords.notificationMedia, predicate: predicate)
let operation = CKQueryOperation(query: query)
operation.recordFetchedBlock = { record in
records2Delete.append(record.recordID)
}
operation.queryCompletionBlock = { cursor, error in
print(records2Delete.count)
}
CKContainer.default().privateCloudDatabase.add(operation)
notificationMedia is a global static var that I also use to save said records, so it cannot be wrong/different. notificationMedia是一个全局静态变量,我也使用它来保存所述记录,因此它不会出错/不同。
Set the zoneID
of operation
because right now you are querying the default zone. 设置operation
的zoneID
,因为现在您正在查询默认区域。
let operation = CKQueryOperation(query: query)
operation.zoneID = zone2D.zoneID
I think I found the answer. 我想我找到了答案。 I was using a deprecated method to save my record. 我使用了不赞成使用的方法来保存记录。
let customRecord = CKRecord(recordType: remoteRecords.notificationMedia, zoneID: zone2D.zoneID)
I changed it to this.. 我改成了这个
let customID = CKRecord.ID(recordName: remoteRecords.notificationMedia, zoneID: zone2D.zoneID)
let customRecord = CKRecord(recordType: remoteRecords.notificationMedia, recordID: customID)
Now I find my records in the sharedDatabase on the cloudKit database and when I use the method shown above the zone set as pointed out by rmaddy I find my records. 现在,我在cloudKit数据库的sharedDatabase中找到了我的记录,当我使用rmaddy指出的区域集上方显示的方法时,我找到了记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.