开发者

Updating Sqlite from web server?

I am currently building an iPhone app that is using Core Data and sqlite databases where the user will be reading static information from the database throughout the app. I have the issue where we may update the information in the database but not want to do a full up开发者_JS百科date of the app, just the database. Can someone please help me out with either a easy function or a tutorial of how to go to a website or server and download the file which will replace the database that we have already put into the app? I'm new in xcode and I`m doing my first app.... thanks for your help


I think what would be a good idea is for your website to publish the data that must be stored in sqllite over REST, possibly in JSON or XML format.

This blog post describes how you could do just that. I must say that its approach to retrieving the content from the webservice is kind of low-level but it'll get the job done. Maybe RestKit can help you take care of all the low-level networking/http stuff.


I assume you want the static data locally so you don't require a constant internet connection for your app to work. Another option is to request the static data from the web and persist it in a file (NSUserDefaults etc...). But, that depends on how complicated the static data is and whether you have to query into that data. If you need to issue queries on that static data, a DB is definitely better.

You can also do a combination where you download updated DB if available async while your app works. You could have a setting in user defaults which is the current static data DB. If updated, you switch the current setting and re-establish the DB connection under a lock.

Here's how to make an http request using iOS.

rest web services in iphone

If you're downloading db data, don't convert the NSData to a string like in that sample ...

Also, ASI-HTTP-Request is popular. Here's samples on how to download a file:

http://allseeing-i.com/ASIHTTPRequest/How-to-use

http://www.cocoadev.com/index.pl?NSUserDefaults

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜