0

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?

Machavity
  • 30,841
  • 27
  • 92
  • 100
GOAT
  • 601
  • 2
  • 13
  • 25

1 Answers1

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:

enter image description here

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.

Community
  • 1
  • 1
asgoth
  • 35,552
  • 12
  • 89
  • 98