Fetching deleted shared records with `CKFetchRecordZoneChangesOperation` does not call `recordWithIDWasDeletedBlock`

Hello.


I am not receiving a response in the `recordWithIDWasDeletedBlock` for `CKFetchRecordZoneChangesOperation` for items that have been shared with me, but deleted by the person who shared them.


For example, say a user shared a photo album with me that contains many photos. The person who shared it with me deleted a photo from the photo album. When I as the user who the album was shared with request changes to the shared database with `CKFetchRecordZoneChangesOperation`, the `recordWithIDWasDeletedBlock` does not get called when performing the `CKFetchRecordZoneChangesOperation` operation.


I do get changes from the `recordChangedBlock` but the `recordWithIDWasDeletedBlock` is never called.


Thanks for any insight you can provide.

Here's my sample code:


func fetchChanges(in recordZoneIDs: [CKRecordZoneID]) {

    let operation = CKFetchRecordZoneChangesOperation(recordZoneIDs: recordZoneIDs,
                                                      optionsByRecordZoneID: nil)

    var recordsToSave = [CKRecord]()
    var recordIDsToDelete = [CKRecordID]()

    operation.recordZoneFetchCompletionBlock = { _, changeToken, _, _, error in
     
        if let error = error {
            // TODO:- Handle error
            return
        }
     
        if let changeToken = changeToken {
            // TODO:- Update change token
        }
    }

    operation.recordZoneChangeTokensUpdatedBlock = { _, changeToken, _ in
        // TODO:- Update change token
    }

    operation.fetchRecordZoneChangesCompletionBlock = { error in
     
        if let error = error {
            // TODO:- Handle error
            return
        }
     
        // Functions that save records to local cache
        self.save(recordsToSave)
        self.delete(recordIDsToDelete)
    }

    operation.recordWithIDWasDeletedBlock = { recordID, _ in
        recordIDsToDelete.append(recordID) // This never gets called even when a shared record has been deleted :(
    }

    operation.recordChangedBlock = { record in
        recordsToSave.append(record)
    }

    CKContainer.default().sharedCloudDatabase.add(operation)
}

Replies

I have the same problem.

the same for me. What is the solution?

Be sure to pass the previous change tokens into the fetch operation.


// Look up the previous change token for each zone

var optionsByRecordZoneID = [CKRecordZoneID: CKFetchRecordZoneChangesOptions]()

for zoneID in zoneIDs {

let options = CKFetchRecordZoneChangesOptions()

options.previousServerChangeToken = // RETRIEVE THE CHANGE TOKEN YOU SAVED PREVIOUSLY FOR THIS ZONE

optionsByRecordZoneID[zoneID] = options

}

let op = CKFetchRecordZoneChangesOperation(recordZoneIDs: zoneIDs, optionsByRecordZoneID: optionsByRecordZoneID)

Did you have any success resolving this issue? I am running into the same issue.

This works fine for private databases, but the issue is with a shared database. Specifically records created by a share participant that is later deleted ... the 'owner' can pass in the change token and call CKFetchRecordZoneChangesOperation, but the recordWithIDWasDeletedBlock isn't called with information about the deleted record.