How to keep plist stored in documents directory in sync between iPhone & iPad for universal app?

时间:2023-02-06 12:39:38

I have a setup in which I have a single plist file that I need to be kept in sync between devices for a universal app. At present the plist file is stored in the documents directory.

我有一个设置,其中我有一个plist文件,我需要在通用应用程序的设备之间保持同步。目前plist文件存储在文档目录中。

I have been looking around online for ways to keep the file in sync and a lot of solutions seem to be based around Core Data. I'm not sure if it's possible, but is there a way I can just sync this one file without using Core data? If so, please can someone advise on how to approach the problem or point me in the direction of some materials that can assist?

我一直在网上寻找保持文件同步的方法,很多解决方案似乎都是基于Core Data。我不确定它是否可行,但有没有办法可以在不使用Core数据的情况下同步这个文件?如果是这样,请有人可以就如何处理问题提出建议,或者指出一些可以提供帮助的材料?

To be more specific I need a way of ensuring that the device being used has the most up to date copy of the plist file. For example, if I edit it on my iPad at breakfast, then at lunch time I load the app on my iPhone I should see the edits made at breakfast time via my iPad.

更具体地说,我需要一种方法来确保所使用的设备具有最新的plist文件副本。例如,如果我在早餐时在iPad上编辑它,那么在午餐时间我将应用程序加载到我的iPhone上我应该看到通过我的iPad在早餐时间进行的编辑。

2 个解决方案

#1


0  

iCloud automatically backs up all the documents directories for all apps (or selective) on your device if you have iCloud Backup turned on in settings.

如果您在设置中打开了iCloud Backup,iCloud会自动备份设备上所有应用程序(或选择性)的所有文档目录。

But the above things happen I guess once in a day. In order for it to work real time you will have to use iCloud API's.

但是上面的事情发生在一天我想。为了使其实时工作,您必须使用iCloud API。

Hoping this helps.

希望这会有所帮助。

#2


0  

AFAIK you will require to provide the iPhone/iPad app with server APIs for making a POST request. You can POST the entire file or create POST request with body (JSON/XML) containing actual data from plist file. You will have to maintain ETag/Versioning information on the server. For synching to work, you need to identify each user uniquely on the server and store his plist information.

AFAIK您需要为iPhone / iPad应用程序提供服务器API以发出POST请求。您可以POST整个文件或使用包含plist文件中实际数据的body(JSON / XML)创建POST请求。您必须在服务器上维护ETag / Versioning信息。要进行同步工作,您需要在服务器上唯一标识每个用户并存储他的plist信息。

In the iPhone/iPad app during every app launch check for the resource ETag (in case file is uploaded) or for version (in case plist file contents were posted as XML/JSON) by making a HTTP request. You can also develop a scheduler functionality in the application for better precision. In case of update, download and save the new information/plist file. Keep entry for ETag/version in the application NSUserDefaults and update it during this process.

在每个应用程序启动期间的iPhone / iPad应用程序中,通过发出HTTP请求检查资源ETag(在上载文件的情况下)或版本(如果plist文件内容作为XML / JSON发布)。您还可以在应用程序中开发调度程序功能,以获得更高的精度。如果更新,请下载并保存新信息/ plist文件。在应用程序NSUserDefaults中保留ETag / version的条目,并在此过程中更新它。

Friendly advice: Avoid storing any downloadable data/settings in Application_Home/Documents directory as app may get rejected. Please read this post and related documents on Apple's developer portal.

友好建议:避免在Application_Home / Documents目录中存储任何可下载的数据/设置,因为app可能会被拒绝。请阅读Apple开发人员门户网站上的这篇文章和相关文档。

This is just initial thought, improvising and optimizing this is for you to figure out ... :)
I hope this helps!

这只是最初的想法,即兴创作和优化这是让你弄清楚... :)我希望这有帮助!

Cheers!!
Amar.

干杯!!阿马尔。

#1


0  

iCloud automatically backs up all the documents directories for all apps (or selective) on your device if you have iCloud Backup turned on in settings.

如果您在设置中打开了iCloud Backup,iCloud会自动备份设备上所有应用程序(或选择性)的所有文档目录。

But the above things happen I guess once in a day. In order for it to work real time you will have to use iCloud API's.

但是上面的事情发生在一天我想。为了使其实时工作,您必须使用iCloud API。

Hoping this helps.

希望这会有所帮助。

#2


0  

AFAIK you will require to provide the iPhone/iPad app with server APIs for making a POST request. You can POST the entire file or create POST request with body (JSON/XML) containing actual data from plist file. You will have to maintain ETag/Versioning information on the server. For synching to work, you need to identify each user uniquely on the server and store his plist information.

AFAIK您需要为iPhone / iPad应用程序提供服务器API以发出POST请求。您可以POST整个文件或使用包含plist文件中实际数据的body(JSON / XML)创建POST请求。您必须在服务器上维护ETag / Versioning信息。要进行同步工作,您需要在服务器上唯一标识每个用户并存储他的plist信息。

In the iPhone/iPad app during every app launch check for the resource ETag (in case file is uploaded) or for version (in case plist file contents were posted as XML/JSON) by making a HTTP request. You can also develop a scheduler functionality in the application for better precision. In case of update, download and save the new information/plist file. Keep entry for ETag/version in the application NSUserDefaults and update it during this process.

在每个应用程序启动期间的iPhone / iPad应用程序中,通过发出HTTP请求检查资源ETag(在上载文件的情况下)或版本(如果plist文件内容作为XML / JSON发布)。您还可以在应用程序中开发调度程序功能,以获得更高的精度。如果更新,请下载并保存新信息/ plist文件。在应用程序NSUserDefaults中保留ETag / version的条目,并在此过程中更新它。

Friendly advice: Avoid storing any downloadable data/settings in Application_Home/Documents directory as app may get rejected. Please read this post and related documents on Apple's developer portal.

友好建议:避免在Application_Home / Documents目录中存储任何可下载的数据/设置,因为app可能会被拒绝。请阅读Apple开发人员门户网站上的这篇文章和相关文档。

This is just initial thought, improvising and optimizing this is for you to figure out ... :)
I hope this helps!

这只是最初的想法,即兴创作和优化这是让你弄清楚... :)我希望这有帮助!

Cheers!!
Amar.

干杯!!阿马尔。