我成功地在私有数据库中创建了一个自定义区域,然后尝试为该自定义区域创建订阅,但是订阅创建失败,并显示错误:“一个错误,指示某些项目失败,但操作总体上成功。”]]
ios文档建议使用CKRecordZoneSubscription创建区域订阅。但是我仍然会出错。我该如何解决?
var ContactZonePrivateDb: CKRecordZone = CKRecordZone(zoneName: Cloud.PrivateZone.Contact.ZoneName)
func createCustomContactInfoZone (completion: @escaping (Error?) -> Void){
let status = UserDefaults.standard.bool(forKey: Cloud.PrivateDB.CustomZoneCreated)
if status == true {
return
}
let createZoneGroup = DispatchGroup()
createZoneGroup.enter()
let createZoneOperation = CKModifyRecordZonesOperation(recordZonesToSave: [ContactZonePrivateDb], recordZoneIDsToDelete: [] )
createZoneOperation.modifyRecordZonesCompletionBlock = { (saved, deleted, error) in
if error != nil {
if let ckerror = error as? CKError {
self.aErrorHandler.handleCkError(ckerror: ckerror)
}
completion(error)
}
UserDefaults.standard.set(true, forKey: Cloud.PrivateDB.CustomZoneCreated)
self.subscribePrivateZoneContact()
completion(nil)
}
createZoneGroup.leave()
createZoneOperation.qualityOfService = .userInitiated
self.privateDB?.add(createZoneOperation)
}
func subscribePrivateZoneContact() {
let status = UserDefaults.standard.bool(forKey: Cloud.PrivateZone.Contact.SubscriptionID)
if (status == true) {
return
}
let subscriptionZone = CKRecordZoneSubscription(zoneID: ContactZonePrivateDb.zoneID)
let operation = CKModifySubscriptionsOperation(subscriptionsToSave: [subscriptionZone], subscriptionIDsToDelete: nil)
operation.modifySubscriptionsCompletionBlock = { saved, deleted, error in
guard error == nil else {
if let ckerror = error as? CKError {
self.aErrorHandler.handleCkError(ckerror: ckerror)
}
return
}
UserDefaults.standard.set(true, forKey: Cloud.PrivateZone.Contact.SubscriptionID)
DispatchQueue.main.async {
print("Successfully added Private zone subscription.\(self.ContactZonePrivateDb.zoneID)")
}
}
operation.qualityOfService = .userInitiated
self.privateDB?.add(operation)
}
我成功在私有数据库中创建了一个自定义区域,然后尝试为该自定义区域创建订阅,但是订阅创建失败,并显示错误:“错误,指示某些项目...
如果您在CloudKit仪表板中删除订阅,然后运行一次订阅创建代码,它仍然显示错误吗?
发现要在定制区域上创建订阅,您必须首先在定制区域中创建一条记录。但这不是其他订阅的情况。为什么呢?