关于 ios:我需要增量获取 CloudKit 更改以及订阅吗? | 珊瑚贝

Do I need to delta fetch CloudKit changes as well as subscriptions?


我正在尝试实现 CloudKit 订阅。以前,我只是在我的应用程序启动时和在我的应用程序的关键点使用 CKServerChangeToken 从自定义区域获取。

我的设置纯粹使用私有数据库。

我只是想知道,如果我转而使用订阅,是否还需要进行这种类型的获取?从我看到的文档中并不清楚。

我使用 CKSubscriptionOptionsFiresOnRecordUpdate 并循环访问所有记录类型来注册通知,而不是使用订阅查询。


是的,即使你实现了CKQuerySubscription,你仍然需要使用CKServerChangeToken。这就是典型的(据我所见)CloudKit 应用程序如何工作以保持其数据同步:

  • 启动时获取 – 当应用启动或再次激活时,检查您的 CKServerChangeToken 并获取任何新数据。
  • 从通知中获取 – 从后台更新记录(即静默)推送通知,因为它们来自您的记录 CKQuerySubscription,以便您的数据新鲜。
  • Apple 将通知描述为”尽力而为”,这意味着有时它们不会到达(相信我,有时它们不会到达)。因此,我发现定期获取新更改(例如每隔几分钟)很有用,以防我的应用错过更改通知。

    这里是一些关于如何注册对 Task 记录类型的所有更改的示例代码:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    let subscription = CKQuerySubscription(recordType:”Task”, predicate: NSPredicate(value: true), subscriptionID:”subscriptionTask”, options: [.firesOnRecordCreation, .firesOnRecordUpdate, .firesOnRecordDeletion])

    let info = CKNotificationInfo()
    info.shouldSendContentAvailable = true
    info.alertBody =”” //This needs to be set to improve notification priority
    subscription.notificationInfo = info

    let operation = CKModifySubscriptionsOperation(subscriptionsToSave: [subscription], subscriptionIDsToDelete: nil)
    operation.modifySubscriptionsCompletionBlock = { subscriptions, subscriptionIDs, error in
      //…
    }

    let container = CKContainer(identifier:”…”)
    container.privateCloudDatabase.add(operation)

    希望对你有帮助。

    • 好问题。是的,您确实在启动时注册了 CKQuerySubscription。但只要您设置了 subscriptionID(例如:”subscriptionTask”),它将无害地覆盖 CloudKit 服务器上的相同订阅,并且您的应用程序将继续收到有关 Task 更改的通知。


    来源:https://www.codenong.com/52193289/

    微信公众号
    手机浏览(小程序)

    Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

    Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

    Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8719.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
    0
    分享到:
    没有账号? 忘记密码?