1

I was wondering whether one could run a HTML page from the iOS device's hard drive, using Objective-C only as a view port to the HTML page and having the HTML page be the application's actual interface. Is this possible to do?

Thanks,

Odinulf

1
  • 2
    Look into PhoneGap and/or Sencha Touch 2. Both do this. Commented Apr 26, 2012 at 15:29

5 Answers 5

2

for IOS create a file with the following:

#import "WrapperViewController.h"

@implementation WrapperViewController

- (void) viewDidLoad
{
  NSBundle *bundle   = [NSBundle mainBundle];
  NSString *path     = [bundle bundlePath];
  NSString *fullpath = [NSBundle pathForResource:@"index" ofType:@"htm" inDirectory:path];
  [webView loadRequest:[NSURLRequest requestWithURL: [NSURL fileURLWithPath:fullPath]]];
}

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
{
  return YES;
}
- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation
{
  webView.scalesPageToFit = YES;
  WebView.backgroundColor = [UIColor blackColor];
}

- (void) didReceiveMemoryWarning
{
  [super didReceiveMemoryWarning];
}

- (void) dealloc
{
  [super dealloc];
}
@end

(I got this straight out of the book "HTML5 for IOS and Android: A Beginner's Guide" [page 388-390])

And this is how you would do it for android.

Hope this helps!

Sign up to request clarification or add additional context in comments.

1 Comment

return something in the 'shouldAutoRotate...' function.
1

Yes it is possible. You need to subview a UIWebView and then load a request pointing to the HTML file in your local directory instead of a web URL. All of your web pages need to be added to the application bundle.

 UIWebView *webview;
 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"page_name" ofType:@"html"]isDirectory:NO]]]

2 Comments

Does this have any limitations? Desktop browsers typically run in a crippled mode if you use the file protocol. Does mobile Safari behave similar?
The only problem that I have noticed is getting the webview to recognize files within subdirectories (if that is how you set up your website and most are set up that way). One answer to this is to place all files in the same directory (a pain in the a I know). There must also be other better solutions
0

Yes it is possible. But, be careful, apple sometimes refuses it. This is what we call Web application.

As Matt points out, take a look at PhoneGap or Sencha Touch

http://phonegap.com/

http://www.sencha.com/products/touch/

Comments

0

Sounds like http://phonegap.com is what you are looking for.

Comments

0

I've worked with phonegap with Android and am impressed with it. Haven't tried it with IOS but here's the link PhoneGap

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.