Showing posts with label UIWebView. Show all posts
Showing posts with label UIWebView. Show all posts

Show Local HTML Files in UIWebview

//loading local html file into UIWebview
NSBundle *bundle=[NSBundle mainBundle];
NSString *filePath = [bundle pathForResource:@"index" ofType: @"html"];
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:fileUrl];
[webview loadRequest:request];

//you can also show .doc .ppt .xls files in UIWebview with NSURLRequest

Getting URL From UIWebView

NSString *currentURL = myWebView.request.URL.absoluteString;
NSLog(@"%@", currentURL);


// or you can get requested pages link before loading page starts if you set your webview's delegate and implement webView:shouldStartLoadWithRequest:navigationType method

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    NSString *requestedLink = [[[webView request] URL] absoluteString];
    NSLog(@"%@",requestedLink);
    return YES;
}