Sharing code between a Web Applicationa and an iPhone App - php

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.

Related

Connect AngularJs to local server php MySQL

Total beginner question (apologize in advance for the stupidity :( )
I am trying to learn how to develop apps using ionic framework/angular.
I created a simple news feed (UI part of it anyway).
I then installed MySQL, PHP and Apache on my Mac (MAMP). I have created some tables and inserted some dummy data.
Now, I am completely lost on what kind of routine/procedure to write on my server, and what code to write in my Angular service so i can show the dummy data in my app?
Basically, how do these two discreet "things" on my system know how to connect and exchange data?
I googled it for few days, but most tutorials don't seem to address this basic question.
I don't actually expect somebody to take me through the steps, but if you can point me to some tutorials/resources on this, it would be much appreciated.
Thanks in advance.
You will have to think in terms of web/RESTful services to expose data to your Angular app. I can point you to a couple of introductory tutorials on the MEAN stack (MongoDB, Express, Angular, Node), but you'll get the idea:
Learn to Build Modern Web Apps with MEAN
Mastering MEAN: Introducing the MEAN stack
Several references to online resources, by ericdouglas
Since you are using AngularJS, your frontend app is a single-page app I suppose. All data your frontend app based on is provided by your backend, here is PHP/MySQL.
You need to use PHP to create a REST service to provide JSON data, which can be consumed by AngularJS app. While MySQL is behind your PHP app as a storage provider, it doesn't talk to your AngularJS app directly.

Building a native mobile application - based on a PHP web-app [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have had a PHP application developed. I want to use phonegap.com or a similar approach to develop native applications based on the same MySQL database. In other words, connect the mobile applications with the web one.
It needs to do one or two things differently. Firstly, use the native GPS features to determine where a user is - I'm guessing this can just be done via HTML5?
Secondly, send push notifications whenever the web-application user receives a notification.
All of the information is already there, on the MySQL database, and everything apart from the two features above function properly.
I'm am currently having an API developed for everything on the web-application - making it API-centric. In my head, it will be easy to connect the two versions via the API.
For example, a user signs up on the web application. He is then offered to iphone app for download.
Is it possible to get him to log-in with the same via the iPhone. On the other side, is it possible for him to search the database, via the iphone, and "add a new friend" - making the connection of the two users in the friends table - in that, the friend is also a friend on the web-application?
I've been reading a lot on all of the available options and am still very confused! Any help would be very helpful.
I'm not a phone developer myself, however I've just finished building a native Android App which connects to a website and is able to login, do stuff that is possible to do on the website as well. If the GPS tracking integration is using the native features than it is unlikely to use HTML5 (though I'm not sure how it works).
Basically in order to connect to a remote database/server you need to make HTTP requests from the phone to you server side script.
So just to conclude:
In order to achieve the result you're looking for the work-flow could look like this:
1.Mobile user fills a form ->
2.App does an HTTP request to a server side script ->
3.script does the hard work (e.g. connects to the database) ->
4.script renders a result ->
5.Mobile app displays the result.
I hope this helps.
Im my objective opinion there are three possibilities:
Get started with Objective-C
You will have to learn how to code and you will get the best native experience for your users. This will easily allow you to use the GPS positioning or you can cache content on your phone. A key problem with the internet connection on the phone is that the internet connection can be flaky. So you have to design for this. You took the right approach already: using the direct MySQL C-API to connect directly to the database server would not work that well, because this protocol is not stateless. You have to first login to the server and then you can send your SQL queries.
By using your API which is hopefully stateless, maybe even a RESTful API, then you can take some nice shortcuts for your native iPhone app. You could then use the RestKit library to easily convert your JSON answers from the server into objects, do caching and other nice features.
Write a web app
The second possibility would be to build a nice web app using state-of-the-art HTML5 technologies. The great thing about that is that you then would write an Android app as well as both mobile devices use a webkit browser. Well it is not exactly the case as there are different versions of Android out there with different screen sizes, but in general this assumption holds. Take a look at Google's web app for Google Calendar for example, I think it is a good compromise. You can also get a home screen icon for this and you will have no app approval process and can update anytime. Using HTML5 offline storage gives you some degree of freedom.
Using Phonegap
The option of writing the app in PhoneGap or some other HTML wrapper framework which will generate Objective-C code is a possible one, but in my opinion this is not really a good option. The reason is that you are working on some kind of intermediate layer and if anything goes wrong or you encounter bugs you will have to dive down to objective-c anyways. The other problem is concerning updates of iOS. It can break some dependencies and then you have to wait until your intermediate gets updated to use the new features.
Phonegap would be a good idea to develop this app. Phonegap although supports client side script only - which means you cannot embed php in its code. However you can easily create AJAX calls in your script that get and send data from your already developed php app/api.
Phonegap also supports GPS and data storage options where you can store the data locally and sync later when internet is available.
For reverse sync (server to client), you would have two options.
1. Create a javascript to make frequent ajax calls to check for updates.
2. Use Push Notifications (Here a tutorial for iOS APNs and Phonegap integration) - http://devgirl.org/2012/10/19/tutorial-apple-push-notifications-with-phonegap-part-1/
Using phonegap depends on one's preference. On the positive side, you save on time/cost as same code is used for all platforms. On the negative side, it has a slight lag when changing pages causing it to look like a website, but you can avoid that by using something like jquery mobile to prefetch all pages and then animate them back and forth. This will also help in uploading data in a separate independent thread while the user would be free to roam around the app.
Hope that helps.
Simply put, the best way to go is for you to use a php web service with phone gap.
You can also go through android using PHP and android. This is a very good and simple way to go. Try the tutorial here
You may tray Xamarin (part of .Net) with the free version of Visual Studio Community and then interact with your PHP web-app. You can then compile the native Xamarin app (written in C#) to Android and iOS.

How should I make my PHP API work for an iPhone app

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.

What is the easiest way to integrate iPhone app with Web Sites that don't have web service

I am about to offer an iphone app for a travel agency. They probably use web services but if not what can I do? What is the easiest way to integrate an iPhone app that read and send data to a website without web service. Site is built with php (I dont know php am a java guy). What can I do for that? Client is a travel agency has a website for ordering hotels.
You can still use NSURLConnection to connect to the site and get its HTML. You just need to have a good parser that can deal with the website and use it like a person would with a browser.
If the site is not cooperating with you, it's not really a good idea. Either, it breaks their Terms of Service or they might just randomly change their site around and your app will break. Usually this isn't because they are trying to break your app -- they just don't know about it, and they are just trying to keep their site up to date.
If you are cooperating, you don't have to go as far as a SOAP webservice -- or even a complex API. They just need PHP that dumps out something easy to parse and that is guaranteed not to change.

How to make my server work with an iPhone app?

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.

Categories