在CloudKit中,添加记录后,新记录将不会立即出现在查询中。怎么解决呢? [英] In CloudKit, after adding a record, the new record will not appear in a query that is conducted right away. How to solve it?

查看:66
本文介绍了在CloudKit中,添加记录后,新记录将不会立即出现在查询中。怎么解决呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CloudKit开发一个iOS应用。我有一个问题:使用 CKModifyRecordsOperation 添加记录后,如果我立即使用 CKQueryOperation 进行查询记录,则通常最新的记录不会出现在查询结果中。似乎最新记录将出现在写入操作几秒钟后进行的查询中。那么,如何解决呢?

I am developing an iOS app using CloudKit. I have a problem: After adding a record using CKModifyRecordsOperation, if I do a query right away using CKQueryOperation to get all the records, then usually the newest record doesn't appear in the query result. It seems that the newest record will appear in queries that are conducted several seconds after the writing operation. So, how to solve it?

在我的应用程序中,当用户添加新记录时,该应用程序将刷新所有记录的列表。但是在大多数情况下,该列表不会包含新记录。只有在用户稍后刷新列表之后,记录才会出现。

In my app, when the user add a new record, then the app will refresh the list of all the records. But in most cases, the list will not have the new record. Only after the user refresh the list later, the record will appear.

推荐答案

我为同样的问题不休,并与之交谈Apple支持获得正式答案:

I banged my head against the same issue and talked to Apple support to get an official answer:

您所描述的行为是预期的,因为CloudKit将花费一些时间来对更改建立索引,而尚未建立索引的记录将无法获得。

"The behavior you described is expected because CloudKit will take a while to index the changes and the records that are not indexed yet won’t be returned.

解决方案是,如果数据位于私有数据库的自定义区域中,则使用CKFetchRecordChangesOperation;如果使用的是公共数据库,则使用默认值

The solution is to use CKFetchRecordChangesOperation, if the data is in a custom zone of the private database. If you are using the public database, or the default zone of the private database, think about this:


  1. 进行更改的设备知道更改。[含义:保留更新的缓存。您做出]

  2. 其他对等设备使用CKQuerySubscription观察更改。

这篇关于在CloudKit中,添加记录后,新记录将不会立即出现在查询中。怎么解决呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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