I'm using CloudKit in my app and have begun by following the best practises in the WWDC video"CloudKit Best Practises"
The first thing to do is to check for changes which I do like so,
let changesOperation = CKFetchDatabaseChangesOperation(previousServerChangeToken: databaseChangeToken)
changesOperation.fetchAllChanges = true
changesOperation.recordZoneWithIDChangedBlock = { self.recordZoneWithIDChanged($0) }
changesOperation.recordZoneWithIDWasDeletedBlock = { self.recordZoneWithIDWasDeleted($0) }
changesOperation.changeTokenUpdatedBlock = { self.changeTokenUpdate($0) }
changesOperation.fetchDatabaseChangesCompletionBlock = { self.fetchDatabaseChangesCompletion($0, isMoreComing: $1, error: $2) }
privateDatabase.add(changesOperation)
There are records in the private database that I am setting up the fetch for, but I only ever get the changeTokenUpdatedBlock and the fetchDatabaseChangesCompletion.
Am I right in saying I should expect to see recordZoneWithIDChangedBlock being hit when I run this operation and my private database's default zone to be passed in to this block?
It means when I call my fetchDatabaseChangesCompletion, there's nothing to fetch because the array of record zone IDs is empty: (note, error is nil)
fileprivate func fetchDatabaseChangesCompletion(_ newToken: CKServerChangeToken?, isMoreComing: Bool, error: Error?)
{
if let error = error
{
// Handle error
return
}
let fetchZoneChangesOperation = CKFetchRecordZoneChangesOperation(recordZoneIDs: changedRecordZoneIDs,
optionsByRecordZoneID: nil)
fetchZoneChangesOperation.recordChangedBlock = { self.recordChanged($0) }
fetchZoneChangesOperation.recordWithIDWasDeletedBlock = { self.recordWithIDWasDeleted($0, string: $1) }
fetchZoneChangesOperation.recordZoneFetchCompletionBlock = { self.recordZoneFetchCompletion($0, newChangeToken: $1, clientSentChangeTokenData: $2, isMoreComing: $3, error: $4) }
fetchZoneChangesOperation.completionBlock = { self.fetchRecordZoneChangesCompletion() }
privateDatabase.add(fetchZoneChangesOperation)
}
I ran into this same problem and it is due to
CKFetchDatabaseChangesOperationandCKFetchRecordZoneChangesOperationonly working on custom zones. CloudKit really wants developers to compartmentalize data so they support more capabilities in custom zones.CKRecordZone
default()ReferenceCKFetchRecordChangesOperationwas deprecated in iOS 10 and replaced withCKFetchRecordZoneChangesOperation.