Как получить уведомление, если владелец удаляет меня из CKShare на CloudKit

Допустим, владелец записи делится этим со мной. Я получаю ссылку для обмена, открываю и принимаю эту ссылку следующим образом:

let operation = CKAcceptSharesOperation(shareMetadatas: [metadata])
operation.acceptSharesCompletionBlock = { error in
  if let error = error{
    print("accept share error: \(error)")
  }else{
    //Share accepted...
  }
}
CloudKit.container.add(operation)

Я также ранее подписался на общую базу данных уже так:

let subscriptionSharedDatabase = CKDatabaseSubscription(subscriptionID: "subscriptionSharedDatabase")
let sharedInfo = CKSubscription.NotificationInfo()
sharedInfo.shouldSendContentAvailable = true
sharedInfo.alertBody = "" //This needs to be set or pushes don't get sent
subscriptionSharedDatabase.notificationInfo = sharedInfo

let subShared = CKModifySubscriptionsOperation(subscriptionsToSave: [subscriptionSharedDatabase], subscriptionIDsToDelete: nil)
CloudKit.sharedDB.add(subShared)

Но теперь, скажем, владелец CKShare удаляет меня как участника этой записи и сохраняет обновленный список участников в CloudKit.

Насколько я могу судить, единственное уведомление, которое я получаю, это еще одна подписка на общую базу данных (subscriptionSharedDatabase) меняются, но никакие записи не изменяются или удаляются (я смотрел, и нет никаких измененных записей, когда я их получаю).

Насколько я знаю, единственный способ получать уведомления об изменениях участников на CKShare подписаться на уведомления на cloudkit.share тип записи, но это не доступно для меня в общей базе данных, верно?

Как я могу получить уведомление, когда меня удаляют из CKShare?

0 ответов

Interesting how this has no answers. I just implemented some CKShare-related code and it seems to work fairly predictably. Here is the basic approach.

1) at the start of my app, I do CKFetchRecordZonesOperation.fetchAllRecordZonesOperation() on the shared database, to get all the current record zones that are shared with me.

2) I set up CKDatabaseSubscription on the shared database as you suggest.

3) Upon receiving this notification on the shared database, I do a batch CKFetchRecordZoneChangesOperation across all the shared record zones. (You can pass it multiple record zones, together with a server change token for each zone, to do a bulk updates query.)

4) If any shares were unshared but the record zones themselves are still valid, I observe that the recordWithIDWasDeletedBlock is run twice, once with the unshared CKRecord and once with the related CKShare.

5) (I didn’t yet fully figure out this part) if the share was the last one for a given user, the whole shared record zone from that user gets removed from my shared database. I didn’t yet fully figure out how to best handle this part. I could query for fresh record zones every time I get a CKDatabaseNotification, but that seems wasteful. I see that I can run CKFetchDatabaseChanges operation that informs me of changed zones, but I have yet to figure out when is the best time to run it.

Другие вопросы по тегам