Many times we need integration between native iPhone application and a web application. This could be due to several reasons. One possibility is that you already have a web application and you can build a native mobile app much quickly by leveraging some part of it. Second is that the web application has been built by a third party and you would like to use it in your application. Example of this is the twitter application, where you can view a link directly inside the twitter application.
Open Browser from App
The simplest case is when you just want to open the browser from your application. You can do this by the function
// Create the URL string NSString* urlString = [NSString stringWithFormat:@"http://maps.google.com/ maps?q=%@", @"india"]; // Launch the browser! [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
This is a very simple approach, however with several disadvantages. One is that your application is no longer running in the foreground. Also your application does not have any control over the web application that has been opened.
Open link within app
The next way is opening a link within the application. It is easily achieved by using a UIWebView as follows:
// Create the web view UIWebView* webView = [[UIWebView alloc] initWithURL:@"http:// maps.google.com/maps?q=%@", @"india"];
This can be added to any view in your application. Now we can close the webview from our application when we need to. In addition, we get callbacks for page loading, link clicks and so on.
The above code would print Send Event.
NSString * nsstrPath = [ [ NSBundle mainBundle ] pathForResource : @"MapsApi" ofType : @"html" ] ; NSURL * nsURL = [ NSURL fileURLWithPath : nsstrPath ] ; NSURLRequest * nsURLRequest = [ NSURLRequest requestWithURL : nsURL ] ; [ webView loadRequest : nsURLRequest ] ;
We hope this article shall help you creating mobile app using iOS and HTML5. We would love to hear your feedback so please feel free to add your comments. There are many frameworks which can help you creating mobile app. We prefer Sencha touch though.