CloudKit:CKFetchRecordChangesOperation,CKServerChangeToken和Delta Download [英] CloudKit: CKFetchRecordChangesOperation, CKServerChangeToken and Delta Download

查看:235
本文介绍了CloudKit:CKFetchRecordChangesOperation,CKServerChangeToken和Delta Download的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与Delta Download有关,因为它是在WWDC 2014 Advanced CloudKit中命名的。

My question is related to the "Delta Download" thing as it was named in WWDC 2014 Advanced CloudKit.

我正在尝试为我的核心数据进行同步应用程序,现在只是iPhone(想想:只有一个设备处于活动状态)。所以,基本上应用程序会将用户记录存储在同一台设备的云中,目前大多数情况都是如此。

I'm trying to make syncronization for my Core Data app, which is iPhone only for now (think: there is only one device active). So, basically the app will store user records in the cloud from one same device, for the most cases for now.

我无法理解基于自定义区域的功能on CKFetchRecordChangesOperation aka Delta Download。

I have trouble with understanding custom zone feature which is based on CKFetchRecordChangesOperation aka Delta Download.

我说得对,我们有 CKServerChangeToken 用于维护同步操作(我的意思是仅下载由其他设备添加/修改/删除的记录),如WWDC上所示。
但是,我无法理解的是,我们只在 CKFetchRecordChangesOperation 之后收到该令牌,当我们将记录保存到云时,我们没有获得新令牌。

As I got it right, we have CKServerChangeToken's to maintain sync operations (I mean download only those records which was added/modified/deleted by another device), as was presented on WWDC. But, what I can't understand is that we recieve that token only after CKFetchRecordChangesOperation, when we save records to the cloud we don't get new token.

如果我们使用当前可用令牌进行提取(因为它仅在获取后更改),我们会收到从之前的保存操作中保存的记录。基本上我们得到了我们设备上已有的保存记录。为什么?我在这里遗漏了什么?

And if we make fetch with the current available token (since it changes only after fetch), we recieve records that was saved from our previous save operation. Basicaly we get save recods that already have on our device. Why? I'm missing something here?

如果我们将一些数据播种到云(来自设备A),如果设备B获取区域记录的情况是合理的,但是如果设备A是什么?再次下载所有记录?

What if we seeding some data to the cloud (from device A), it is justified for situation when device B is fetching the zone records, but what if device A be? Download all the records again?

我在 CKRecord recordChangeTag $ c>,这是一个我可以用来解决与本地对象冲突的属性 - 获取的对象(相同或不同的版本),如果是这样,有人可以举例说明我需要这样做:保存记录时将recordChangeTag保存到Core Data第一次使用CloudKit还是第一次?

I found recordChangeTag in the CKRecord, is this a property I can use for resolving conflicts with local objects - fetched objects (same or different version), if so can somebody give me example of how I need to do this: save recordChangeTag to Core Data when save record to CloudKit for the first time or how?

缺少文档令人头疼。

推荐答案

我找到时间为这个问题写一个答案。我不会深入了解实现,但我将讨论这个概念。

I found a time to write an answer for this question. I won't dig into implementation, but I will discuss the concept.

CloudKit提供了一种在设备和CloudKit服务器之间进行数据同步的方法。
我在iPhone和服务器之间用于建立同步过程的情况(再次,如果你有iPhone + iPad应用程序,这个过程需要更多步骤。):

CloudKit provides a way to data synchronisation between your device and the CloudKit server. What I use to establish synchronisation process in my case between iPhone and server only (again, if you have iPhone + iPad app, the process require more steps.):

我在私有云数据库中有自定义区域。
我使用OperationQueue来建立彼此依赖的不同异步进程。某些操作具有自己的操作队列。

I have custom zone in the private cloud database. I use OperationQueue to establish different asynchronous processes which depend on each other. Some operations have own operation queues.

步骤:

1)检查我的自定义区域是否存在

1) Check if my custom zone is exist

1.1)如果没有自定义区域

1.1) If there is no custom zone

1.2)创建新的自定义区域。 (可选:添加记录)

1.2) Create new custom zone. (Optional: add records)

1.3)刷新区域更改标记

1.3) Refresh zone change token


您可以刷新区域更改令牌:执行
CKFetchRecordChangesOperation
fetchRecordChangesCompletionBlock 返回 CKServerChangeToken
使用NSKeyedArchiver将其保存到UserDefaults(例如)。此操作的任务是刷新令牌,并在结束同步过程中执行。

You can refresh zone change token by: performing CKFetchRecordChangesOperation, fetchRecordChangesCompletionBlock returns CKServerChangeToken save it to UserDefaults (for example) using NSKeyedArchiver). This operation's task is to refresh token and it's performed at the end synchronisation process.

2)如果已经有自定义区域

2) If there is custom zone already

2.1)使用以前保存的区域更改令牌从区域获取更改。 ( CKFetchRecordChangesOperation

2.1) Get changes from zone using previously saved zone change token. (CKFetchRecordChangesOperation)

2.2)更新和删除本地记录。

2.2) Update and delete local records.

2.3)刷新区域更改令牌。

2.3) Refresh zone change token.

2.4)检查本地更改(我正在使用上一个云同步时间戳以检查修改后的记录。)

2.4) Check for local changes (I'm using last cloud sync timestamp to check what records was modified after).

2.5)将记录上传到云套件数据库

2.5) Upload records to cloud kit database

2.6 )再次刷新区域更改标记。

2.6) Refresh zone change token again.

我强烈推荐Nick Harris文章系列: https://nickharris.wordpress.com/2016/02/09/cloudkit-core-data-nsoperations-introduction/

I highly recommend Nick Harris article series: https://nickharris.wordpress.com/2016/02/09/cloudkit-core-data-nsoperations-introduction/

您将找到实施和设计概念。值得一读。我希望有人会发现所有这些都有帮助。

You'll find there implementation and design concepts. It worth reading. I hope somebody'll find all of this helpful.

这篇关于CloudKit:CKFetchRecordChangesOperation,CKServerChangeToken和Delta Download的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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