What is the best way to achieve database synchronization? - iphone

I am looking to build software that has an Iphone application as well as a Wordpress based website. Essentially the user will enter data into the iphone app that will then be relayed to the Wordpress site and displayed in various manners.
Whats the best way to get the iphone database and CMS database to communicate?
Thanks

This might go without saying, but generally speaking I would try to keep your client (iPhone) app as 'dumb' as possible; Your Wordpress DB should really own all of the content, and the data stored on the iPhone should be as temporal as possible. To put it another way, your app should be like a WP theme. A theme doesn't really 'know' about the WP database - it's just responsible for displaying it (and occasionally adding to it with things like comment forms).
Anyway, as for the actual communication I would recommend keeping as much in JSON as possible (I've found it easier than XML). There's a great plug-in for Wordpress that can help you out, that exposes WP functionality in a JSON-based API: http://wordpress.org/extend/plugins/json-api/
As for working with JSON on the phone itself, I highly recommend the json-framework: http://code.google.com/p/json-framework/ . In short, it'll convert a JSON string into an NSDictionary in one method. Incredibly useful.
Good luck!

May be it's too obvious, but usually for database communicaton used XML, CSV, JSON etc.

Related

How to get data into Core-Data from an SQL Database?

I'm about to start an iOS project that requires pulling user's data from an SQL Database and viewing it within the App. Before I begin I'm looking for conformation that I'm taking the right (best) route.
My Plan:
App starts on login page (app will display data from another service)
App uses AFNetworking to post request to web service
Web service gets user data from SQL Database and sends back JSON
App uses JSONKit to parse the feed and load into Core-Data
App uses info from core-data to populate UI
Does this seem like an appropriate way to get the info into Core-Data from SQL? Any suggestions for doing things differently?
Thanks.
Are you receiving the response from the web server in JSON? If so, the fact that the server is using an SQL database is immaterial. What you need to know is how to parse JSON for inclusion in a core data store. Cocoa is my Girlfriend has a pretty good tutorial up.
Part 1
Part 2
To answer your comment, here's what I've done.
Display a login screen. The login credentials should be stored in the keychain for security. I've used SSKeychain for this.
To handle sending and receiving data from a web request your best option is to use a pre-built library. I've always used ASIHTTPRequest, but since it is no longer under active development, you should probably look around a bit before you commit to anything. I'm sure there are nicer and cleaner libraries out there.
You need to parse the JSON responses. I'm a fan of JSONKit. It's very fast, very easy to use, very robust.
Pulling data out of the core data store and displaying it in the interface will be no problem for you. If you create a new project in Xcode most of the setup will be done for you.
Now, there are a lot of projects out there that attempt to combine web requests, json parsing and core data loading into one framework. I've tried to use a few of these and haven't had much luck. The ones I've tried haven't been robust and very difficult to debug. Setting up your own request/parse/load code is not difficult at all, just a bit time consuming.
I am sure that there are a lot os ways to make implement this problem. Your solution is one of the popular solutions I guess but you could connect to the DB via a socket and talk with the database directly e.g. Going over a port 80 web site has the advantage that the possibility of some kind of firewall blocking the communication is very low. I would solve this kind of problem the same way I guess.

Sending Data to Website From iPhone

I'm creating an iPhone Game where I want the user to get a unique numeric code when they first launch the app, that way when a friend of that user opens it, he/she can input that code and both users can get rewarded. I haven't encountered any issues regarding that, however what I want to do is make it to where the app registers the code given to every user and saves it to a website of some sort. That way when the other user enters the code, it will load the data from that website and check if it's registered. How would I manage to save the data onto a website? and also What free website could I use for this without having a character limit on the body page?
-Thanks in advance
Your thinking is correct, in that you need to save your data somewhere online, but you don't really "save data onto a website" in the way that you're describing. "Free Website" services usually serve a different purpose entirely - that of serving up public html pages. Sure, they can take the form of a CMS (like wordpress.com or tumblr accounts), but using that as an interface for storing your application's data is not something they're typically designed to do.
For something like this, where you have a public iPhone app that requires secure access to custom strings, you really want to have control over your own web server (different than a domain name, btw), and interface with a database on that server. This will come at a cost, and will involve more code than you're likely to find someone to write for you on here. Sorry to say it, but hey if someone wants to prove me wrong I'd love to see it.
Because all you need to store & retrieve are random strings (basically referral codes... if I'm understanding correctly), your database needs are pretty simple. If you're not familiar with things like PHP / MySQL, and you don't want to learn, it might be worth reaching out to some server-side developers for help. Unless there's more to it than you describe, you can probably find someone to help you for relatively cheap.
Good luck - and I'm sorry there isn't a simpler answer for ya.
You can send data using NSURLConnection. Just create an NSMutableURLRequest and call its -setHTTPMethod: method with “POST” as the HTTP method. Then, set its body and header fields appropriately, and you can use NSURLConnection to send the data.

What is the best way to connect an iphone app to a mysql database?

I want the way with the fastest execution time. I'm not feeling comfortable of using web service because i need to create separate php pages and retrieve data as xml. If you think its good to use web service please tell me why. I want to code my database queries right on my c/objective c pages.
I've been searching for libraries. I saw this sequel pro - won't i have any problems on using this - like licensing issues? I also saw this libmysqlclient of cocoa but some say its not working well. I've also read about a library developed by Karl Kraft found here http://www.karlkraft.com/index.php/2010/06/02/mysql-and-objective-c/ but don't know if i could trust this.
I would really appreciate you help.
Definitely build a web service to act as an abstraction layer to your database. Here are some significant reasons in my opinion:
Since you want speed, you will be able to add caching when using the webservice, so you will essentially eliminate the need for identical queries to run (sometimes).
If you need to change your data model later, you just have to modify the webservice backend and don't have to update your app.
You can better control security by not exposing the database to the world, and keep it safe behind the web service.
Your database credentials should not be stored in an app. What if you needed to change those?
I strongly suggest a web service. Hope this helps.
Connect to your DB by PHP and output the result as JSON
is much better and faster then xml and less coding if use JSON Framework.
and never never try to connect to your DB from your iphone because it easy to sniff out the request from iphone.
Being safe then Sorry, keep that in mind

iPhone SDK & MySQL Remote Database

I've tried looking around but honestly not finding much help. I am mostly seeking for advice as to how I should approach to develop what I am thinking.
I want to accomplish something like this.
Imagine a website, with a backend database. This database contains information fed by users themselves. The website is fully functional, now I want users to be able to have the same functionality on their iPhones. I don't use a local database because I want all users to be able to have access to the same database, and this changes constantly.
What would be the best approach to:
Allow users to access all the information currently available on the website (database perspective).
Able to edit & add new entries to the database
I don't know if me creating an array to hold all this data would be wise to do. Specially with large amounts of data. I dont know how well it can scale.
Should I create a duplicate SQL lite database on the phone itself duplicating that of that website? What do you guys feel would be a good approach to this?
Comments, links, references would be greatly appreciated.
Thanks!
Sounds like the perfect time to create an API for your website. If the size of you application is not very big, you can use the same database, but would be good to run the API separated from the web server.
Essentially, such an API should allow you to make requests to certain URLs for retrieving, updating and deleting information from the database.
Depending on what server-side platform you are currently using, there are many options.
Client-side, your iPhone app can use http://restkit.org/ or http://allseeing-i.com/ASIHTTPRequest/ if you feel confident.

iphone - retrieving information from the internet (rss alternative?)

(Very) basically my app is just a load of information collected from the internet - eg: someone can log into an admin panel on a website and update their app from there. The information gets put into a mysql database.
The way I thought about going about this was to use an RSS feed - it works for blog/twitter feeds, so I thought why not do it for the rest of the information that I want to get.
My question is, is this a suitable way to do it? Basically just make dynamic XML files (php scripts that output XML) and parse them on the iphone, or is there a better way to do it?
I'm not looking for a full blown tutorial, just maybe a few keywords that I can go off and look up myself - or a "XML is the best way... stick at that". :p
Thanks a lot.
I personally like JSON more than XML, since it creates less characters to transfer the same data = less bandwidth/transfer used and faster response.
You can use a JSON library from here or just stick with XML since you're familiar with it. I guess it's just a matter of personal preference.