Is it possible to mix HTML 5 in with my native app? I want one page to be made with Objective-c and the other with HTML 5. If so can someone direct in the right direction?
Asked
Active
Viewed 91 times
1 Answers
2
Yes it is possible. I did it as a test a few weeks ago. On your storyboard, you just have to drag a WebView
component on, and link it with your ViewController.h
interface. Here is an example of a mixed storyboard. First the UIToolbar
with the buttons was dragged on it, then the WebView
:
When the view loaded (viewDidLoad
) you need to initialize the WebView:
- (void) viewDidLoad {
[super viewDidLoad];
self.webView.delegate = self;
NSURL *url = [NSURL URLWithString:@"http://localhost:8080"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
}
You can communicate between the WebView and iOS. I did an explanation here.
Also if needed, you can setup an internal HTTP Server. I've used CocoaHTTPServer, which is very easy to install with CocoaPods. Just create a Podfile
:
platform :ios
pod 'CocoaHTTPServer', '~> 2.2.1'
and command pod install
from the project directory.