将本地sqlite文件同步到iCloud [英] Syncing a local sqlite file to iCloud

查看:673
本文介绍了将本地sqlite文件同步到iCloud的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的iOS应用程序中直接在本地.sqlite文件中存储一些数据。我选择这样做而不是CoreData,因为数据需要与非Apple平台兼容。

I store some data in my iOS app directly in a local .sqlite file.  I chose to do this instead of CoreData because the data will need to be compatible with non-Apple platforms.

现在,我想提出最好的方法通过iCloud同步此文件。我知道你不能直接同步,出于很多原因。我知道CoreData能够同步它的数据库,但即使忽略使用CD本质上锁定这个文件到苹果平台(我想,我只研究了CD一点),我需要这个文件的iCloud同步工作所有的iCloud的支持平台 - 这应该包括Windows。我必须假设在Windows API中的CoreData文件不会有任何兼容性。如果苹果会告诉我们任何更多的将有一个Windows API [最终?],那么计划实现这一目标的最佳方法将会更加容易。

Now, I'm trying to come up with the best way to sync this file over iCloud.  I know you can't sync it directly, for many reasons.  I know CoreData is able to sync its DBs, but even ignoring that using CD would essentially lock this file into Apple platforms (I think? I've only looked into CD a bit), I need the iCloud syncing of this file to work across ALL of iCloud's supported platforms - which is supposed to include Windows.  I have to assume that there won't be any compatibility for the CoreData files in the Windows API.  Planning out the best way to accomplish this would be a lot easier if Apple would tell us any more than "There will be a Windows API [eventually?]"

,我最终需要实现至少一个同步服务来支持iCloud不支持的平台。这将是有帮助的,虽然不是必需的,如果我用于iCloud的方法可以大部分重用于未来的服务。

In addition, I'll eventually need to implement at least one more sync service to support platforms that iCloud does not.  It would be helpful, though not required, if the method I use for iCloud can be mostly reused for future services.

由于这些原因,我不认为CoreData可以帮助我这个。

For these reasons, I don't think CoreData can help me with this.  Am I correct in thinking this?

从这里开始,我需要为此设计一个算法,或找到一个现有的第三方解决方案。我还没有碰到什么。但是,我一直在研究一些可以实现的方法:

Moving on from there, I need to devise an algorithm for this, or find an existing one or an existing 3rd party solution.  I haven't stumbled across anything yet. However, I have been mulling over a couple possible methods I could implement:

方法1:

类似于CoreData如何同步sqlite数据库:发送事务日志到iCloud,并构建每个本地sqlite文件。

Do something similar to how CoreData syncs sqlite DBs: send "transaction logs" to iCloud instead and build each local sqlite file off of those.

我想每个设备都会发送一个(唯一命名)文本文件,列出该设备执行的所有sql命令,并带有时间戳。设备将存储它已经执行的命令的每个列表中的距离,并且从每次文件被更新时的那点开始继续。如果它一次接收到多个日志文件的更新,它将以时间戳顺序执行每个命令。

I'm thinking each device would send a (uniquely named) text file listing all the sql commands that that device executed, with timestamps.  The device would store how far along in each list of commands it has executed, and continue from that point each time the file is updated. If it received updates to multiple log files at once, it would execute each command in timestamp order.

一旦这些文件变大,但它似乎是一个可解决的问题。

Things could get 'interesting' efficiency-wise once these files get large, but it seems like a solvable problem.  

方法2:

定期将工作数据库的副本同步到iCloud 。在每个记录中都有一个修改时间戳字段。当数据库的更新副本通过时,查询具有比某些参考时间更新的时间戳的所有记录,并从新数据更新本地数据库中的记录。

Periodically sync a copy of the working database to iCloud.  Have a modification timestamp field in every record.  When an updated copy of the DB comes through, query all the records with newer timestamps than some reference time and update the record in the local DB from the new data.

I请使用此方法查看许多潜在问题:

I see many potential problems with this method:

需要进一步实现以识别记录删除。

-Have to implement something further to recognize record deletion.

DB文件可能会发生冲突。可能可以通过以时间戳顺序处理每个冲突版本来处理它们。

-The DB file could get conflicts. It might be possible to deal with them by handling each conflict version in timestamp order.

- 确定检查每个更新的日期可能很棘手,因为它取决于哪个

-Determining the date to check each update from could be tricky, as it depends on which device the update is coming from.

方法2存在许多潜在问题,但方法1似乎对我来说是可行的。

There are a lot of potential problems with method 2, but method 1 seems doable to me...

有没有人对什么是最好的行动方案有任何建议?任何比我的方法1更好的想法(或为什么它不工作的原因)?

Does anyone have any suggestions as to what might be the best course of action? Any better ideas than my "Method 1" (or reasons why it wouldn't work)?

推荐答案

Ray Wenderlich:

Try those two solutions from Ray Wenderlich:

通过邮件导出/导入数据:
http://www.raywenderlich.com/1980/how-to-import-and-export- app-data-via-email-in-your-ios-app

Exporting/Importing data through mail: http://www.raywenderlich.com/1980/how-to-import-and-export-app-data-via-email-in-your-ios-app

使用iTunes共享文件:
http://www.raywenderlich.com/1948/how-integrating- itunes-file-sharing-with-your-ios-app

File Sharing with iTunes: http://www.raywenderlich.com/1948/how-integrate-itunes-file-sharing-with-your-ios-app

我发现它很复杂,但帮了我很多。

I found it quite complex but helped me a lot.

这篇关于将本地sqlite文件同步到iCloud的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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