Reputation: 3168
I have a PHP website that lets users add textual information (notes, posts). I accomplish that by having a database and PHP scripts that insert, delete, edit, and share that info.
Due to the extraordinary success of this product I want to move into the mobile app space. How could I go about wrapping my PHP code in C or Objective-C so that I could re-use this when building an iOS app?
If I can't re-use my PHP code in this manner, how do I go about using C or Objective-C to connect with my database and mimic the functions of the website?
This article shows how to create a login script for an iPhone app using PHP code:
http://kiksy.tumblr.com/post/525713227/iphone-login-app-using-php-mysql-tutorial
Could something similar be done to bring across the rest of my PHP code in an iOS app?
Upvotes: 2
Views: 2598
Reputation: 27597
You can not in any kind reuse your PHP code within a native iOS app. Well, at least not the part that renders the UI (HTML, Javascript). You can reuse all of your business logic (adding posts, getting overviews, deleting posts etc). This would be achieved by wrapping your business logic with a JSON or XML based interface towards your iOS app. Your iOS app would then request the data / initiate the transactions using JSON / XML and render it natively on the device. You would need to entirely rebuild your PHP-based UI part and create an Objective C / Objective C++ based version of it. This might be the right solution in case your application needs a fast, responsive and eye-candy-rich UI. Another point for creating a native app would be sales via iTunes.
You may however use a web-based app on the iOS devices by using your PHP code as a whole. For that scenario, all you will have to do is take the smaller screen and limited network bandwidth into account. Without knowing your exact demands, this solution seems to be the most appropriate one. This will allow you to quickly deploy updates and will widen the audience towards other mobile devices.
A third solution would be something that is commonly called a hybrid app. Such hybrid app uses native parts wherever the demands on UI and processing are high and web parts on the rest. Building a hybrid app will also possibly minimize the costs of implementing further versions needed for Android and other platforms, if desired. This would also allow you to sell via iTunes. From my experience however, hybrid apps suck and are tough to develop and debug as you will end up having to communicate between HTML/Javascript and Objective C/Objective C++ (namely the UIWebView
). Let me get it straight, this is technically totally possible but again, from my experience the results are not as slick and funky as an entire native app. It has however become a trend to use this approach.
Upvotes: 7
Reputation: 3803
Use phoneGap, this way you don't have to create anything from scratch. Use your URL to load into web view phone gap created and you good to go. Link: http://phonegap.com/
Upvotes: 0
Reputation: 9671
Take a look at http://www.appcelerator.com/ which let's you write your code in Javascript (might be easier for you, coming from web work) and compile it for iPhone and Android.
To get the data from your PHP app you will have to provide some kind of webservice.
Upvotes: 0
Reputation: 228
One suggestion would be to use a wrapper library such as this: http://www.swig.org/.
PS: Objective C and C++ can also be used with iPhone development.
Upvotes: 1
Reputation: 6389
You're in a new league. It's not that simple. ground up build is what you need in order to do it correctly
Upvotes: 0