I am working on a social network project in PHP/MySQL. If you have ever seen or used the myspace or facebook iPhone app you will see what my question is all about. I am curious what most iphone apps do with the server for a social network type iphone app. I was tyhinking possibly it uses a REST server with jSON or XML output and possibly the iphone app will just read that? Or does most iphone apps do there own query to a database somehow? Sorry I really don't have any knowledge in that sort of programming so I could be way off on all this.
So basicly what would be the most efficient way for a iphone app to get data from a server?
In my opionion, the ASIHTTPRequest Library, a RESTful Webservice and the JSONTouch library are working great together.
To get you started (including a PHP/MySQL example) take a look at this great tutorial:
iPhone Coding Tutorial – Creating an Online Leaderboard For Your Games
A RESTful approach is almost certainly the cleanest and easiest. The iPhone API has great support for communicating via XML.
There are some fairly comprehensive examples in Apple's Developer Connection.
http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/XMLParsing/XMLParsing.html
You would use JSON or XML web services but you can use whatever HTTP mechanism you like.
Answering the second part of your question no the apps don't normally talk direct to the database but use web services instead.
Related
I posted this question a few weeks ago, but perhaps it came off as vague and wasn't really well accepted. So I'm going to try and be more specific, since I am still looking for an answer.
I have an idea for an iphone app that I wanted to start working on. I'm a Web Programmer by trade, and was considering writing the application initially as a website. (intended for Desktop / Laptop users). Once I figured out all the ideas, I was then going to use that as a blueprint for the iphone app.
My question is: It would be great to have both versions running, and thus, sharing as much code as possible. Is there a practice, methodology, or set of principals for dealing with this sort of scenario? For Example: www.facebook.com and the Facebook iPhone app.
I'm thinking that the endpoints which the iPhone accesses to retrieve data, should be the same code that the Web Application uses to retrieve data. Or with different platforms running, is it common practice to maintain completely separate code bases?
To be clear, my iPhone App would be a native iPhone app.
thoughts?
you can create a webservice for that,you can use json or xml to create webservice response format.
you can use that webservice with any platform. by parsing json or xml you can get your data and display it according to your platform specific design.
If got a task to create a mobile application for iOS, Android and WP. This application needs to access a mySQL database which is already in use by the website running php.
What I found in the meantime, is that I have to create a php webservice and use this webservice to access the data in the mySQL database.
Since I did not found any clear advice which way is the best to do it (JSON, XML, REST, etc) - I just wanted to ask you, is there a kind of best practice which technologies should be used for the php webservice?
Additional it would be great for me if someone knows a good tutorial for the recommended technology.
Thanks a lot.
I am arriving a bit late but here is my answer : I believe that the easier way currently available is a PhoneGap application (with Sencha Touch or jQuery Mobile as a javascript framework) talking to the server through a simple PHP webservice. PhoneGap allows you to build an Android, iOS and WP app with the same codebase.
We use that technology in my company and it works great.
I am a php developer with a few web apps like a project management app and a forum i'd like to move to Android and iPhone.
I've heard of developers using Sencha Touch and PhoneGap to develop native apps and I know they support HTML5, CSS and Javascript, but how abot PHP? And is are there any other APIs/frameworks I should consider that better support local server scripting?
Speaking about webapp, maybe you can avoid building an app by having a mobile enabled version of your website compliant with all the client browsers.
Have a look at jquerymobile, it is compliant with mostly all the mobile browsers and you will be able to reuse your code.
To answer correctly, you can call your webservices using ajax to fetch json/xml/etc data from Phonegap because it is using jQuerymobile ;-)
Have a look at this discussion here on Stackoverflow :
Passing formdata from Phonegap to PHP with JSON
Hope this helps
PHP is a server-side scripting language and your .php files have to be stored on the server side. You can access them asynchronously with Ajax, so no, you can not include php files (with reasonable time and effort) in your app.
The only smart way to go here is native iOS apps, forget PHP, Android and the rest of that crap. By the way I'm not trying to be an iOS snob here but am just reflecting on a few realities. One is that iOS apps can actually make money though a web replacement app might not. The second issue is that going native demands a reboot on your part, that is best done on one platform until you get up to speed. The third issue is that users now a days expect well performing apps that don't have a lot of web cruft in them. Fourth the Android marketplace is screwed, you are far more likely to establish that critical user base on iOS as you can target a handful of platforms running the latest generation of iOS, android is by comparison a pathetic mess of old versions of android running on all sorts of hardware.
On iOS look a BlueAlien as an example of a better than web method of accessing Reddit.
The title may not be the best way to describe my question.
I am working on another social network type site similar to a facebook site in PHP. I would like to eventually pay someone to build me an iPhone/iOS app that will be similar to the facebook iPhone app but work with my PHP site instead.
So a major concern for me will be to have the iOS app to be as fast as possible for the users.
From others experience, what would be the best way for my PHP sites API to get the data for the iOS app? I would think that a simple REST type API that returns results with JSON and XML formats would be the way most sites work with an iPhone/iOS app?
Is my theory correct or is there a different way to do it? Please help
Yes, that's the best solution. The only alternative I know of would be to connect with via TCP/IP, and skip the higher level HTTP protocol. That means using sockets.
I have an existing PHP/MySQL website that relies hugely on form POSTs for things like signing up, logging in, searching etc. I now need to create a native iPhone app for it. The business requires a native app for marketing reasons, I can't get away with a mobile optimized website.
I'm looking for suggestions from someone who has already done this - how did you rewire your website to POST/GET data from the iPhone app? I'm guessing I'll have to send/receive data as XML, which is then parsed by the server and client. Is there anything simpler or any framework that can make this easier?
Thanks!
If you don't have some sort of webservices or API to connect through for the website I would make that my first priority. While you can scrape HTML and send POST requests, it can get quite messy FAST. I've created iPhone apps which talk with webservices through SOAP requests, and have built an iPhone interface to a site, which wasn't pretty. It is very doable, but it is also very frustrating if anything changes on the webpage.
If you are looking for a decent library to help you get started with POSTing against forms check out the ASIHTTPRequest library at http://allseeing-i.com/ASIHTTPRequest/. If you look at the site there is a 'How to Use It' page with 'Sending Data with POST or PUT Requests'. Otherwise you could just use NSURLRequest and NSURLConnection and handle everything yourself.
It depends a lot on what you are presenting. You may be able to put a lot of your php heavy interfaces into web pages. The web pages and all related resources would be local to, and formatted for the iPhone. You can look at PhoneGap for examples of how to host local web pages and communicate with the host application.
I have been writing an eBook reader. About half of the user interface is done through local html files. In my case there is no network access, but WebKit is the easiest way to style text.
As long as your application does not look like a web page, it is fine if it is a web page. That may simplify big chunks of server interaction, especially things like login that only happen once or rarely.
Jonathan,
I would recommend taking a look at the Apple provided SeismicXML sample app. It uses the NSXMLParser to parse XML in a asynchronous fashion which will be huge for your app. It also shows how to use a NSURLConnection to make the request off of the web. You can use the NSURLConnection (which is also asynchronous) for POST/GET requests.
As mentioned in another answer, the ASIHTTPRequest library from allseeing-i.com is an excellent library but all of the features you want can be done using the built in Apple APIs if needed for your business requirements.
Hope this helps!