I'm developing an app using UITableView driven content.
Current testing is done with local XML of size 100kb. This info should update about once every 2 months. The flow is reading pre-sorted XML -> convert to NSDictionary -> UITableView
Since parsing XML will take some work during load every time, plus table index, sorting and searching seems clumsy. So I have this idea about storing such info in a sqlite DB file
My real question is whether it's possible to download the entire sqlite DB file via http(s) instead of XML to update the info?
I don't understand the question...you have a sqlite database on a server somewhere and you want to know if it's possible to download via http? Yes, of course, just open a NSURLConnection and grab the data.
If you want to somehow transform XML from an http source to a sqlite database, well, then you'll have to write your own custom transformation code to get the proper SQL statements--there's no automatic way to do this in Cocoa.
You have a couple of options...
You can keep the stuff on the server
XML and build the database on the
fly.
You could post a text file on
the server with pre-canned insert
statements.
You could just have a
ready made DB file on the server and
download it.
Any would work... Some are more code than others.
Related
I have a Web Service and sqlite database. In this, web service will be used to store data inside database. Now I want to include sync functionality as - Whenever application starts at that time the database will start to load its table's data through web service.
Now after some time when I update my my web service the database will be updated accordingly. My question is that what are the best practices that I must follow for this update. Should I clear whole DB and start adding all rows again(I know this will take a lot time) but If not this then how do my database will add only particular data from the web service?
Thank you.
What I suggest you is:
store all your webservice content into db first when the app starts.
display your content on the screen from db only.
again when you need to refresh or recall your data just update the database.
Thus, you will always find all your fresh data into database.
Downloading and updating the entire server data will prove expensive. It will use more bandwidth and prove costly to your customer. Rather than pushing the entire load (even for minor update), send a delta. I will suggest you to maintain version information.
When application downloads the data from web service for a said version and store it successfully in the database, set the current updated version as well in the DB.
When app starts the next time, make a light weight header request to get just the version info from the server. The server should respond to this header request with the latest data version number.
Check the version from WS with the current application data version stored in the DB. If the server has an updated version, start the sync.
The version change information should be delta i.e.
For new version, server should send only the information that is changed since the version available with the device.
You server should have capability to calculate the delta between two versions.
Delta information will typically have sections like, new data, updated data, deleted data etc.
Based on this, the iOS app will make the necessary CRUD(Create, Read, Update and Delete) operations on the DB data.
Once the iOS app updates itself, then you can update the DB version to the latest received version from server. Until then let it remain dirty for proper error handling.
Hope that helps.
I would recommend you use RestKit's superb Core Data support.
By using RKEntityMapping you can map your remote objects from JSON or XML directly to Core Data entities in your database.
RestKit will automatically maintain the database for you, inserting and updating entries as appropriate from your web service. (In my experience, I've found deleting objects requires a tiny bit of extra work depending on how RESTful your web service is).
RestKit definitely does have a learning curve attached, but it's well worth it: having deployed it a couple of times now, is definitely a much better solution than manually writing your own SQLite/Web Service syncing code.
First you need to set all webservice content into your SQLITE.and what you want to display get that data from SQLITE.and perform opertaion into that sqlite table and when once all this done you need to changes made are saved it into webservice.
Follow this way.
I have an app to send data from iPhone to MySQL server and I got it with request from objective-c and php on server.
Now, I want to receive data from server by XML. I have created a php code to generate data from MySQL to XML. How can I code in objective-c to call this php code? The goal is using this XML to parse and display on iPhone (I have objective-c code to parse xml file from link on server).
Please help me if you know and used to work on that.
Use Web-servces Like XML- RPC, SOAP ,REST
To connect to a mysql database, your best bet is to use JSON/SOAP/XML/PHP or some combo of the mentioned, to talk between your database and your app..
The reason database connection directly from the device is a bad idea, is that you have to enable global external access to it for it to work. You can keep your data safer by having scripts on your server do the communication to the database.
Your server needs to expose a service of some kind (a URL the iPhone app can call).
Your app can call this URL with NSURLConnection (or lots of others).
This will return you an NSData * object.
Your app will then need to parse this raw data into XML (or JSON or a few others). You can use NSXMLParser (and lots of others) to do the parsing.
Then, you need to translate the XML into useful business objects.
This is my first question so I will do my best to conform to the question guidelines.
I am developing an iPhone app that parses and XML feed to be displayed in a table. Parsing is not a problem but I am not sure of the best way to optimize loading times after initial run of the app.
Here is the different approaches that I am considering:
Parse the XML feed each time the application is loaded. Easy way but possibly longer loading time each run of the app.
Grab the feed and store it locally (as .xml) then parse locally. Then, each time the app is opened, make an http call to see if the feed has been changed. If not, parse locally. If so, download the new feed and parse locally. The initial loading time will be longer but could be cut down on later runs (if the feed as not been updated). This option will be beneficial if the user has a bad signal but needs to see the data.
Parse the feed and store it into a local sqlite db. Then, each time the app is opened, make an http call the see if the feed has been changed. If so, detect which objects have been added/removed and alter local db accordingly. If not, load data from local db. This might be the best option but I am not sure how long finding the changes will take.
My feed is only about 100 or so items, each with roughly 20 fields.
Initial parsing time:
Roughly 4-5sec with full bars.
Roughly 5-7sec with 3 bars.
Any insight as to which option would work best would be very much appreciated.
I think the frequency of the xml data changing should be a factor. If its only going to change once a day/week? Id load it, save it, and check for updates. If update exists download new and overwrite old.
Third solution is clearly the best and it will allow your app to work offline and start quickly. To detect the change, you can simply store a MD5 of the xml file in database and match it against the MD5 of the new XML file. If data has changed, then simply discard all previous data.
Is it possible to connect to SQL server in iPhone?. I want to create a new application and i want to retrieve the data from SQL Server and displayed. Previously it created using ASP.NET and SQL Server. Now my client wants to display the datas which is retrieved in SQL server data base. But the database contains the huge amount of data. So is it possible to convert the SQL Server to SQLite.(But SQLite is a light weight components). How can i do that? Can i use Web services? or i will ask to server side and convert the XML file and then i will use XML Parsing. I have no idea about it?
Please Explain Me!
Thanks.
i don't work on an iPhone app but i know that our guys that do use webservices that return pure xml with data, return that to the iphone and then parse that xml.
Wow... You are actually wondering if you can connect your iPhone-application to a SQL-server directly? Are you insane?! If you do, you need to connect with host-, username-, password-, en db-name-parameters. When people 'hack your binary converting it back to the source-code (.m-files)' they can read these parameters and create a custom connection to your db-server.
So, what you need to do is create a few scripts that parse your DB-data and return it as xml-data, so hackers won't be able to loggin into your db-server.
I'm a total noob when it comes to iPhone development and have been tasked to create a database app that can download and upload sqlite data to and from a server via http using web services. So far I already have a form for retrieving and saving data to a SQLite database and now I need some information on how I can upload the SQLite data to a server. The SQLite database will only have one table with 3 columns and about 200 rows max. I hope somebody can point me to the right direction or lead me to some sample codes.
Appreciate any help.
As you are using HTTP to get data into the iPhone, you should also use HTTP to get data out of the iPhone. That way, you can query the SQLITE database and send the data through HTTP to a remote server.
It's pretty simple to accomplish since you have all the HTTP protocol implemented in the SDK.
On the server side, you can use whatever you want: Apache+PHP, Tomcat, JBoss, ASP.NET, you name it.