记录,区域未在仪表板中显示,并且删除区域问题CloudKit [英] Records, Zone doesn't displayed in Dashboard and Delete Zone issue CloudKit
问题描述
我为 privateCloudDatabase
创建了一个区域。
I have created a zone for privateCloudDatabase
.
static var privateCloudDatabase: CKDatabase {
let container = CKContainer(identifier: "iCloud.<bundle>")
return container.privateCloudDatabase
}
static func createZone() {
let fetchZonesOperation = CKFetchRecordZonesOperation.fetchAllRecordZonesOperation()
fetchZonesOperation.fetchRecordZonesCompletionBlock = {
(recordZones: [CKRecordZone.ID : CKRecordZone]?, error: Error?) -> Void in
guard error == nil else {
return
}
for recordID in recordZones.keys {
if recordID.zoneName == zoneName {
print("Zone Already Created: \(recordID)")
} else if recordID.zoneName == "_defaultZone" {
print("Deafult Zone")
} else {
let customZone = CKRecordZone(zoneName: zoneName)
privateCloudDatabase.save(customZone) { zone, error in
if let error = error{
print("Zone creation error: \(String(describing: error))")
} else {
print("Zone created: \(String(describing: zone?.zoneID.zoneName))")
}
}
}
}
}
fetchZonesOperation.qualityOfService = .utility
privateCloudDatabase.add(fetchZonesOperation)
}
工作成功,但我收到了成功消息,但是创建的 Zone
不会显示在CloudKit仪表板中。到目前为止,它仅显示 _default
区域。
It works successfully and I got a success message but created Zone
doesn't display in CloudKit Dashboard. It only shows the _default
zone as of now.
另一个问题与删除<$中的所有数据有关c $ c>区域。为此,我使用了以下代码
The other issue is related to delete all data from Zone
. For that, I used below code
let fetchZonesOperation = CKFetchRecordZonesOperation.fetchAllRecordZonesOperation()
fetchZonesOperation.fetchRecordZonesCompletionBlock = {
(recordZones: [CKRecordZone.ID : CKRecordZone]?, error: Error?) -> Void in
guard error == nil else {
return
}
guard let recordZones = recordZones else { return }
let deletionOperation = CKModifyRecordZonesOperation(recordZonesToSave: nil, recordZoneIDsToDelete: recordZones.keys.map { $0 })
deletionOperation.modifyRecordZonesCompletionBlock = { _, deletedZones, error in
guard error == nil else {
let error = error!
print("Error deleting records.", error)
return
}
print("Records successfully deleted in this zone.")
}
}
fetchZonesOperation.qualityOfService = .userInitiated
privateCloudDatabase.add(fetchZonesOperation)
此处我既未收到任何成功消息,也未收到任何错误消息。我尝试从该区域删除所有数据的另一种方法是
Here I neither get any success message not get any error message. The other method I tried to delete all data from the zone is
let customZone = CKRecordZone(zoneName: zoneName)
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: recordType, predicate: predicate)
privateCloudDatabase.perform(query, inZoneWith: customZone.zoneID) { (records, error) in
if error == nil {
for record in records! {
removeRecord(record.recordID.recordName) { record, error in
}
}
}
}
在这里,我收到了成功消息,但是当我尝试从区域中获取数据时,我得到了所有条目,这表明数据不是' t使用以上任何一种方法删除。对这些查询有任何建议吗?
Here, I get the success message but when I am trying to fetch data from the zone, I get all entries and that suggests data aren't deleted using any of the above methods. Any suggestions for these queries?
推荐答案
每当我遇到莫名其妙的错误并且CloudKit中没有数据更新时,通常是
Whenever I have run into inexplicable errors and the absence of data updates in CloudKit, it was usually because of something silly like:
- 容器标识符中的错字,因此它与CloudKit上的错误数据库进行了交互。
- 我在Apple设备上使用的帐户与我在CloudKit仪表板中登录的帐户不同。
您是否检查过CloudKit日志以确认这些操作是否影响了您的数据库?
Have you checked the CloudKit logs to confirm that these actions are hitting your database?
这篇关于记录,区域未在仪表板中显示,并且删除区域问题CloudKit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!