Reputation: 4164
I'm building an iOS app, and part of the functionality is that it needs to work offline. Right now the app downloads information from a web server by loading a PHP script, which when sends out the data in JSON. So my app would send a request to www.foo.com/bar/getVideos.php. Returning a JSON string of all the videos needed.
I want to be able to have an entire local copy of the database on the device (It's not very big, it would just make things easier for offline use). Is the best way just to get all the tables, and output them in JSON. Then rebuild on the iPhone (assuming I already know the structure, just filling in the data). Or is there an easier way?
Upvotes: 1
Views: 2632
Reputation: 39296
Another option is to build the sqlite database server side and just download the database file. The sqlite file is portable.
That will reduce the complexity and processing time on the device and centralize it on the server.
Upvotes: 2
Reputation: 8707
I think your approach is good enough. And it is very portable – you may easily change a server side software, or even create a client on another platform (e.g., Android), because JSON is very common standard.
Another option you may generate an SQLite DB and then transfer it to iPhone, and use iOS built-in support for SQLite. You may choose any other solution. But you already have a vision how to solve your issue, thus, I think just need to use it.
Upvotes: 1