收到 CKDatabaseNotification 后查询变化

Query Changes after receiving CKDatabaseNotification

我目前正在构建一个应用程序,允许用户使用多个 phones 同时分享活动和签到他们的客人。我设法设置了 CKQuerySubscription 并更新、删除和创建工作正常,但仅在主要 phone(共享事件的那个)上。

我最近发现非主要用户要获得通知,它必须从我设置的 CKDatabaseNotification 获得通知,当我通过 CloudKit 进行更改时它会收到远程通知。仪表板。

但是我收到的通知 (CKDatabaseNotification) 没有任何内容可以让我找到更改的记录。我已经尝试按照 link 上的建议将其转换为 CKNotification,但正如预期的那样,它失败了。

我设置了自定义区域,我的问题如下:

CKDatabaseNotification 只会告诉您发生了某些变化,而不是它是什么。推荐的前进路径是您使用 CKFetchDatabaseChangesOperation 来找出哪些记录区域发生了变化。然后,您在 CKFetchRecordZoneChangesOperation 中使用来自该操作的记录区域 ID 来获取所有更改。

CloudKit Quick Start Guide

中有更多信息

我在下面挑选一些相关信息:

After app launch or the receipt of a push, your app uses CKFetchDatabaseChangesOperation and then CKFetchRecordZoneChangesOperation to ask the server for only the changes since the last time it updated.

The key to these operations is the previousServerChangeToken object, which tells the server when your app last spoke to the server, allowing the server to return only the items that were changed since that time.

First your app will use a CKFetchDatabaseChangesOperation to find out which zones have changed

然后

Next your app uses a CKFetchRecordZoneChangesOperation object with the set of zone IDs you just collected to do the following:

• Create and update any changed records • Delete any records that no longer exist • Update the zone change tokens

WWDC 视频 CloudKit Best Practices 也讨论了这个主题。