how to maintain a local database in iphone
I am a software engineer concentrating on iphone application development and I own a developer license. Currently I am working on a project where i need to maintain a local database in iphone. Each time the application launches , the application should sync data from a remote server. The application should add/update/delete the local table entries corresponding to the data from remote server.
I plan to use SQLite DB. I would like to know whether there is any framework available fo开发者_如何转开发r synchronizing these two databases? Also is there any other DB which is supported by iphone?
I'm also working on this and am going to use Core Data as well. I'm planning on using the Reachability API to determine if I am able to sync, and then use JSON to transfer the data from the remote server. Core Data is really easy to use and you don't have to build SQL directly at all. It also automatically manages keeping objects in memory for you which will help with memory usage like you have in a constrained environment like the iPhone.
I've recently finished a similar app (at least in terms of database functionality), and I've found Core Data to be invaluable. It lets you define a data model - similar to a database schema from your remote database - then you can pull down data in whatever format is most suited to you and store it in Core Data.
The framework will abstract away things like the underlying persistence mechanism, so you can use SQLite (the default) or a couple other data storage formats (XML is an option, IIRC). You can also manipulate the data records in an object-oriented manner, which is incredibly convenient when driving some other parts of your app (like the UI). Take a look at the Core Data Programming Guide for more info.
As for the synchronization framework itself, I'm not aware of anything prebuilt that does what you're looking for. My solution was to let the SQL daemon on the server generate XML (MySQL happens to have a handy command-line option --xml
for just this purpose), then use NSXMLParser on the iPhone end to parse the XML back into Core Data objects (of course other people will recommend libxml - I just stuck with what was most readily available).
精彩评论