I have a UIViewController
class named WebScreenViewController
, which is having an UIWebView
. Here is the class implementation file:
@implementation WebScreenViewController
@synthesize urlString;
- (void)viewDidLoad
{
[super viewDidLoad];
self.webView.delegate = self;
// Do any additional setup after loading the view.
[self gotoUrl:self.urlString];
//[self gotoUrl:@"http://www.google.com"];
}
#pragma mark - UIWebView Delegates
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL* url = [request URL];
NSString* urlStr = url.absoluteString;
NSLog(@"shouldStartLoadWithRequest. URLStr = %@", urlStr);
return YES;
}
-(void)webViewDidStartLoad:(UIWebView *)webView
{
NSLog(@"webViewDidStartLoad");
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString* html = [webView stringByEvaluatingJavaScriptFromString:@"document.body"];
NSLog(@"webViewDidFinishLoad: HTML string = %@", html);
}
-(void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"didFailLoadWithError. ERROR: %@", error);
}
#pragma mark - Member Methods
-(void)gotoUrl:(NSString*)urlStr
{
NSLog(@"Calling website %@ in UIWebView...", urlStr);
NSURL* url = [NSURL URLWithString:urlStr];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:urlRequest];
}
@end
The above code work well on one of my testing device but did not work on another. It worked on my iPod Touch with the latest iOS 8.1.2. But it didn't work on my iPad3 with iOS version 7.0. When I run it on my iPad3, it will call the gotoUrl:
method and the log "Calling website %@ in UIWebView..." will be displayed. And that's it. I receive no more logs from the delegates. To check the internet connections, I tried using Safari on the same device and it was working.