将iOS Core Data与发送XML的远程服务器同步 [英] Syncing iOS Core Data with remote server which sends XML

查看:87
本文介绍了将iOS Core Data与发送XML的远程服务器同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序从远程服务器解析XML并将对象存储在Core Data(SQLite存储)中。因此,用户可以通过从本地存储中读取来在OFFLINE时浏览材料。

My app parses XML from remote server and store the objects in Core Data(SQLite storage). So that user can browse the material when OFFLINE by reading from local storage.

用户可以在离线浏览时对对象进行更改,这些对象会在本地存储在Core Data SQLite存储中。另一个用户对远程服务器上的对象进行了一些更改,并将其存储在那里。现在当我检测到互联网连接时,我的应用程序应该将本地存储与远程服务器同步。这意味着远程服务器会在我离线时对我的核心数据(SQLite存储)所做的更改进行更新,而我的本地存储 - 核心数据(SQLite存储)需要更新其他用户对远程服务器所做的更改。

User may make changes to objects when browsing offline which gets stored locally in Core Data SQLite store. Another User makes some changes to object on Remote server and it is stored there. Now when I detect internet connection, my app should sync my local storage with remote server. Which means remote server is updated with changes I made to my Core Data(SQLite storage) when I was offline and my local storage - Core Data(SQLite storage) needs to be updated with what ever changes other user made to remote server.

例如,有一个论坛,它存储在我的本地存储空间中,以便我在旅行时可以阅读和回复。以后在互联网上访问。我的应用程序应该自动将我的所有回复存储在核心数据中到远程服务器,并将远程服务器上的其他帖子带到我的本地存储中。

For example there is a forum and it is stored in my local storage so that I can read and reply when I am traveling. When later on internet is accessible. My app should automatically put all my replies stored in core data to remote server and also bring other posts on remote server into my local storage.

远程服务器正在发送我正在解析并存储在Coredata中的XML。 我的问题是如何同步它?
如果发生变化,两种沟通方式如何发生?
如何仅同步已更改的数据而不是IMPORT整个远程服务器数据库,反之亦然?

Remote server is sending XML which I'm parsing and storing in Coredata. My problem is how to sync it ? How both ways communication happens when there is a change? How to sync only data which has changed and not to IMPORT whole remote server DB and vice-versa ?

推荐答案

我知道其中一种方法。


  1. 在本地和服务器数据库中再添加一个字段。即,时间戳。

  2. 当用户更改本地数据库上的数据时,将时间戳更改为当前时间。
    在服务器上执行相同操作。当有人编辑服务器上的数据时,将时间戳更改为当前时间。

  3. 当用户连接到互联网时...检查本地时间戳到服务器时间戳..
    案例1两者都相同 - 无所事事
    案例2当地时间>服务器时间 - 使用sql获取时间戳大于服务器时间戳的所有数据..并将其上传到服务器上...
    case 3 local< server ....获取大于本地时间戳的所有记录并将其添加到本地数据库..

我不确定如果有更好的方法......但这肯定有效...

I am not sure if there is any better way... but this surely works...

这篇关于将iOS Core Data与发送XML的远程服务器同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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