how can I check SyncEngine status
Opened this issue · 0 comments
playmyswift commented
thanks for this great project,
when I develop a app, I want to check icloud sync status,
Expected behavior
print(syncEngine.status)
// failed, syncing, done ....
Actual behavior(optional)
syncEngine has't status property
Steps to reproduce the problem(optional)
in DataManagerProtocol.swift
, status propetry should be set in modifyOpe.modifyRecordsCompletionBlock
?
public func syncRecordsToCloudKit(recordsToStore: [CKRecord], recordIDsToDelete: [CKRecord.ID], completion: ((Error?) -> ())? = nil) {
let modifyOpe = CKModifyRecordsOperation(recordsToSave: recordsToStore, recordIDsToDelete: recordIDsToDelete)
modifyOpe.isAtomic = true
modifyOpe.modifyRecordsCompletionBlock = {
[weak self]
(_, _, error) in
guard let self = self else { return }
switch ErrorHandler.shared.resultType(with: error) {
case .success:
DispatchQueue.main.async {
completion?(nil)
}
case .retry(let timeToWait, _):
ErrorHandler.shared.retryOperationIfPossible(retryAfter: timeToWait) {
self.syncRecordsToCloudKit(recordsToStore: recordsToStore, recordIDsToDelete: recordIDsToDelete, completion: completion)
}
case .chunk:
/// CloudKit says maximum number of items in a single request is 400.
/// So I think 300 should be fine by them.
let chunkedRecords = recordsToStore.chunkItUp(by: 300)
for chunk in chunkedRecords {
self.syncRecordsToCloudKit(recordsToStore: chunk, recordIDsToDelete: recordIDsToDelete, completion: completion)
}
default:
return
}
}
database.add(modifyOpe)
}