load html page on to UI web view iphone SDK 4.0 - iphone

I want to load html page on to UI web view.
i'm developing using iphone sdk 4.0
Thanks

You can use this method for complex User Interface in iPhone View Controller. Because we can create ".html" page easily and use this method to display complex UI
UIWebView *webView = [[UIWebView alloc] init];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"]isDirectory:NO]]];
[webView setUserInteractionEnabled:YES];
[webView setScalesPageToFit:YES];
[self.view addSubview:webView];
[webView release];

Related

Is there a template XCode project I can use for making an iOS app that just shows a webpage?

I want to make an iPhone/iOS app that, when opened, simply launches a UIWebView with a particular page and does nothing else. Is there a template XCode project I can use to help accelerate the process for me a little?
No, Xcode does not provide such a template. You can, however, use the "Single View Application" template and it should be pretty easy to do with Storyboards.
Here's a tutorial: http://www.youtube.com/watch?v=bGPJeYxWr3Y
There is no template. But you can just create a new project "Single View Application". Then set in Interface Builder your view to a UIWebView and add some lines to load your required website, e.g. viewWillAppear.
CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0);
UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];
[webView setBackgroundColor:[UIColor clearColor]];
NSString *urlAddress = #"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
[webView release];
put this in the viewDidLoad of your single view applications view controller and you have it.. :)
There is a shell app for the same on GITHub.
https://github.com/endymion/iOS-HTML5-Shell-App/
But as the author says, do the world a favor and don't use it.
Not exactly a template, but you could just drop this into your project and use it. It's a drop in UIWebView. http://cocoacontrols.com/platforms/ios/controls/web-browser-view-controller

UIWebView: Images are not updating

I am using UIWebView to load HTML Page. From that HTML I have generated PDF file. My PDF file content changes as per the HTML data changes. when I change the Signature(Image) of the user in application respective PDF will not change to new signature. It shows the previous signature.
How can I reload that UIWebView?
[webView reload] should do the trick.
If you are using a new URL you can use [webView loadRequest:[NSURLRequest requestWithURL:theURL]];
If you are using same url with updated content use this.
UIWebView* webV=[[UIWebView alloc]init];
NSString* htmlString= #"Loading...";
[webV loadHTMLString:htmlString baseURL:nil];
[webV loadRequest:[NSURLRequest requestWithURL:mainURL]];

How to open web page in web view on iPhone

I want to open web page on the webView by passing the web url of that page. How is this possible?
You can load a website using this:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://i.wrightscs.com"]]];
You can also load HTML into a UIWebView using this:
[webView loadHTMLString:#"<strong>It Work's!</strong>" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];

Can't load JavaScript from Resource in UIWebView

I am loading a local HTML file into a UIWebView in iOS using this code
NSString *urlAddress = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"];
NSURL *url = [NSURL fileURLWithPath:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
The page works fine, and the image linked within the HTML loads fine. However, the JavaScript linked off of the page is not loading.
The HTML, Image and JavaScript are all located in the same folder. (Resources/Html in my Project)
How can I get the JavaScript to load?
The problem was that XCode was showing me a warning:
warning: no rule to process file
'$(PROJECT_DIR)/html/orientation.js'
of type sourcecode.javascript for
architecture i386
This answer contains the solution. Basically, I had to tell XCode to not try and build the JavaScript files, and manually drag them to the "Copy Bundle Resources" directory.
The following code works for loading an html file which has javascript files in the web view
Here web is web view object and index is the html page
Web.delegate = self;
[Web loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"]isDirectory:NO]]];

Facebook in iPad: UIWebView - renders as touch instead of standard web

Up until a few days ago it worked fine: opening facebook.com in iPad/UIWebView rendered as standard web. Now Facebook is force-rendered as touch - as if the URL was http://touch.facebook.com. This happens regardless of the UIWebView frame size. Here is a simple code for the main view controller to see the problem:
UIWebView *wv = [[UIWebView alloc] initWithFrame:self.view.frame];
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.facebook.com"]];
[wv loadRequest: req];
[self.view addSubview: wv];
I tried changing the user agent as suggested here - no good.
Using http://www.facebook.com?m2w should resolve this. "m2w" sounds like it is short for "mobile 2 web", and it's the link that you arrive at when you click "full site" from the mobile site.