如果所有者将我从CloudKit的CKShare中删除,该如何通知 [英] How to Be Notified if the Owner Removes Me from a CKShare on CloudKit

查看:100
本文介绍了如果所有者将我从CloudKit的CKShare中删除,该如何通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设某个记录的所有者与我分享了该记录。我收到一个共享链接,然后打开它并接受这样的共享:

Let's say the owner of a record shares it with me. I get sent a share link and I open it and accept the share like this:

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)

我以前也已经订阅了 Shared 数据库,就像这样:

I am also previously subscribed to the Shared database already like so:

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。

But now let's say the owner of the CKShare removes me as a participant on that record and saves the updated participants list to CloudKit.

据我所知,我收到的 only 通知是另一个共享数据库订阅( subscriptionSharedDatabase )更改,但没有记录被更改或删除(我查看并且获取记录时也没有更改记录)。

As far as I can tell, the only notification I get is another shared database subscription (subscriptionSharedDatabase) change, but no records are changed or deleted (I looked and there are no changed records when I fetch them).

据我所知,唯一的通知方式 CKShare 上参与者的更改的一部分是订阅 cloudkit.share 记录类型上的通知,但这不是

As far as I know, the only way to be notified of changes to the participants on a CKShare is to subscribe to notifications on the cloudkit.share record type, but that isn't available to me in the shared database, right?

当我从 CKShare

推荐答案

有趣的是它没有答案。我刚刚实现了一些与CKShare相关的代码,它似乎可以预见地工作。这是基本的方法。

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)在我的应用开始时,我执行 CKFetchRecordZonesOperation.fetchAllRecordZonesOperation()在共享数据库上,以获取与我共享的所有当前记录区域。

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)我设置了 CKDatabaseSubscription 根据您的建议在共享数据库上。

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

3)在共享数据库上收到此通知后,我进行了 CKFetchRecordZoneChangesOperation

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)如果未共享任何份额,但记录区本身仍然有效,我观察到 recordWithIDWasDeletedBlock 运行了两次,一次与未共享的 CKRecord 一起运行与相关的 CKShare

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)(我尚未完全弄清楚这部分)是给定用户的最后一个,则该用户的整个共享记录区将从我的共享数据库中删除。我还没有完全弄清楚如何最好地处理这一部分。每当我得到 CKDatabaseNotification 时,我都可以查询新的记录区域,但这似乎很浪费。我看到我可以运行 CKFetchDatabaseChanges 操作,该操作会通知我已更改的区域,但是我还没有弄清楚何时是运行它的最佳时间。

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.

这篇关于如果所有者将我从CloudKit的CKShare中删除,该如何通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆