Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

url not loading in UIWebView

Tags:

i have a tab bar control. 1st tab contains a navigation control. On the 2nd tab i want to load a web page (say google.com). I have written the code as

NPIViewController.h

@interface NPIViewController : UIViewController {
   IBOutlet UIWebView *webView;
}
@property (nonatomic,retain) IBOutlet UIWebView *webView;
@end

NPIViewController.m

- (void)viewDidLoad {
  [super viewDidLoad];
  NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; 
  NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
  [webView setScalesPageToFit:YES];         
  [self.webView loadRequest:request];               
}

The page just does not load. No compilation or runtime errors. What is wrong in this ?

like image 302
Ashish K Agarwal Avatar asked Apr 13 '11 06:04

Ashish K Agarwal


People also ask

Is UIWebView deprecated?

Apple is phasing out UIWebView, which is used by developers for integrating web content into an app in a quick and secure manner. Apple is replacing UIWebView (and WebView) with WKWebView, an updated version, as UIWebView has been deprecated.

When was UIWebView deprecated?

New apps containing these frameworks are no longer accepted by the App Store. And last year, we announced that the App Store will no longer accept app updates containing UIWebView as of December 2020.

What is UIWebView safari?

It means that your web site was viewed using the UIWebView functionality on an iOS device (iPhone, iPad, iPod Touch). The UIWebView is different from the ordinary Safari browser, as it is not a stand-alone browser, but merely browser functionality that is embedded in a third party app.


1 Answers

to know whats wrong you can do this.

- (void)viewDidLoad {
  [super viewDidLoad];
  webView.delegate = self;
  NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; 
  NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
  [webView setScalesPageToFit:YES];         
  [self.webView loadRequest:request];               
}

add this new method in your class

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
   NSLog(@"Error : %@",error);
}

I hope you have connected webView object with its outlet in Interface builder?

Thanks,

like image 173
Ravin Avatar answered Oct 11 '22 21:10

Ravin