SJTriggs
SJTriggs

Reputation: 476

Connecting a MySql database to an IOS application

Basically I need to connect a MySql database to an IOS application and save a local copy to the device but i'm confused about which path I should take to do this.

Here is a basic description of the application: The application is used to replace multiple paper based forms, allowing the user to complete a desired form on an iPad. Once the user has completed the form, the forms data is uploaded to a server.

Some forms have fields where the user is required to 'select' an option (drop down list). These options need to be pulled from a database because the options will be changed regularly.

The application still needs to work if there is no internet connection!

This means that whenever there is a connection the application needs to save a copy of the current database so that any required information to fill out forms is still available even if there is no connection.

In short my question is: What is my best option to save a local copy of a database (or just a few tables) to an IOS application?

Upvotes: 0

Views: 198

Answers (1)

trevorj
trevorj

Reputation: 2039

You should look into Core Data. If you're trying to keep an updated copy of a couple tables, I would create a Core Data database that contains the information you need for your app and, every time the user uses your app, check to see if there's an internet connection. If there is, use NSURLSession to download the necessary data from the web server, after which you can compare the downloaded data to that which is in your Core Data database. If there are any discrepancies between the two, you can update your Core Data database as needed. This way you will always have a relatively up-to-date copy of your MySQL database.

This is a good tutorial for getting a feel for NSURLSession in case you haven't used it much.

Hope it helps!

Upvotes: 1

Related Questions