我使用的CKQueryOperation显然对我的大多数用户都很好。然而,对其中一些人来说,这是行不通的。问题是queryCompletionBlock没有被调用。
分析用户日志--我可以看到,它对大多数用户都很好,但对少数用户却不起作用。它在所有类型的iPhone模型中都失败。但是iOS总是在失败的设备上使用iOS 14.2。不幸的是,我无法在我的设备上重现这个问题,这使得无法对其进行调试。
我已经检查过这个问题与互联网连接类型(wifi或数据)无关。
有什么想法吗?
这是密码
func fetchTeams(_ success: @escaping (_ result: [CKRecord]?) -> Void,
failure: @escaping (_ error: NSError) -> Void) {
bfprint("fetchTeams starts")
let type = RecordType.Team
let predicate = NSPredicate(format: "TRUEPREDICATE")
let query = CKQuery(recordType: type.rawValue, predicate: predicate)
let operation = CKQueryOperation(query: query)
allTeamsRecords = []
executeQueryOperation(operation,
success: success,
failure: failure)
}
private func executeQueryOperation(_ queryOperation: CKQueryOperation,
success: @escaping (_ result: [CKRecord]?) -> Void,
failure: @escaping (_ error: NSError) -> Void) {
bfprint("executeQueryOperation starts")
let configuration = CKOperation.Configuration()
configuration.qualityOfService = .userInitiated
queryOperation.configuration = configuration
queryOperation.queuePriority = .veryHigh
queryOperation.recordFetchedBlock = { [weak self] (record) in
guard let strongSelf = self else {
bfprint("CloudKitDataProvider was deallocated before we got all team records")
return
}
strongSelf.allTeamsRecords.append(record)
}
queryOperation.queryCompletionBlock = { [weak self] (cursor, error) in
bfprint("fetch teams operation completion block called")
if let cursor = cursor {
bfprint("We got a new cursor fetching teams")
let newOperation = CKQueryOperation(cursor: cursor)
guard let strongSelf = self else {
bfprint("CloudKitDataProvider was deallocated before we got all team records")
return
}
strongSelf.executeQueryOperation(newOperation,
success: success,
failure: failure)
}
else if let error = error {
DispatchQueue.main.async(execute: {
failure(error as NSError)
bfprint("Cloud Query Error - Fetching Teams): \(error)")
})
}
else {
DispatchQueue.main.async(execute: {
bfprint("Get teams finished successfully")
guard let strongSelf = self else {
bfprint("CloudKitDataProvider was deallocated before we execute success closure")
return
}
success(strongSelf.allTeamsRecords)
})
}
}
Self.publicDB.add(queryOperation)
bfprint("query added to database")
}发布于 2021-01-31 11:39:10
我百分之九十九肯定是iOS的问题。在用户更新到iOS 14.3之后,问题消失了
发布于 2020-12-10 18:41:43
我不知道在您的情况下有什么特别的错误,但是我可能会提供一些关于CloudKit的一般性指导,因为我已经使用它多年了。CloudKit确实是可靠的,但也有点不可靠。:)
以下是一些建议:
data.
因此,在您的示例中,您可能有一种方法可以反复尝试CKQueryOperation,以便在CloudKit上出现混乱时重新尝试。维护与CloudKit同步的本地缓存是确保数据准确的最佳方法。
https://stackoverflow.com/questions/65130700
复制相似问题