简体   繁体   English

如何在iOS应用中远程存储数据?

[英]How do you store data remotely in an iOS app?

I have an app that relies on some key value pairs where the value could change at a point in the future due to 3rd party api. 我有一个依赖于某些键值对的应用程序,由于第三方API的影响,该值在将来的某个时刻可能会发生变化。 The app is only useful when connected to the internet by the way. 该应用程序仅在顺便连接到互联网时才有用。 If any values change I don't want issue a new version of the app - I would rather that these values were pulled from a webservice/static xml file on my server. 如果有任何值更改,我不想发行该应用程序的新版本-我希望这些值是从服务器上的webservice / static xml文件中提取的。 I would only need to pull these if I encountered an error. 如果遇到错误,我只需要拉出它们。

Is there a standard way to do this or should I just roll my own? 有标准的方法可以做到这一点,还是我应该自己动手做?

EDIT: I'm not so interested in a server side technology - I think a flat file will suffice. 编辑:我对服务器端技术不是很感兴趣-我认为一个平面文件就足够了。 What I'm interested in is what format should the flat file should be and how to cache it into my application once I get an error. 我感兴趣的是平面文件应采用哪种格式,以及在遇到错误后如何将其缓存到应用程序中。

try redis, high-performance key-value store. 尝试使用Redis高性能键值存储。 used by some of the big cloud players, like cloudfoundry. 一些大型云厂商(例如cloudfoundry)使用的。 Have a look at http://redis.io/ . 看看http://redis.io/ Objective-c client is available at http://redis.io/clients . 可从http://redis.io/clients获得Objective-c客户端。

I figured out the best way for my use scenario: 我想出了使用场景的最佳方法:

I setup a json file on S3 which required authentication. 我在S3上设置了一个json文件,该文件需要身份验证。 I then used AWS for Objective C to authenticate so I could access that file. 然后,我将AWS用于Objective C进行身份验证,以便可以访问该文件。

I decided that I only needed to update the local info when the applicationDidBecomeActive in the App Delegate. 我决定仅在App委托中的applicationDidBecomeActive时才需要更新本地信息。 I then got the json async and on success I then checked a version number in the json and if outdated wrote the changes to NSUSerDefaults (which are then used through the app.) If there was an error getting the json file I just continued as I would already have the previous set of NSUserDefaults that would do the job until the user next made the app active. 然后,我得到了json异步信息,并且成功后,我检查了json中的版本号,如果过时,将更改写入NSUSerDefaults(然后通过应用程序使用。)如果获取json文件时出现错误,我将继续我将已经具有之前的NSUserDefaults集,该组NSUserDefaults可以完成工作,直到用户接下来激活该应用程序为止。

This solution worked best for me as it's simple to maintain and should easily handle the load even if my app were popular. 该解决方案对我来说效果最好,因为它易于维护,即使我的应用很受欢迎,也应该可以轻松处理负载。

Have you considered using iCloud? 您是否考虑过使用iCloud? It has support for key value pairs. 它支持键值对。 More info here: http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/iCloud/iCloud.html 此处的更多信息: http : //developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/iCloud/iCloud.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM