1

I use uiwebview on my ios application. I have textbox above it and it navigates the uiwebview. I enter m.youtube.com and the webview perfectly loads it. I made a search on the youtube.com and the results is loaded perfectly. When I click any of the video I go to the video page, and I want to have that url link of the page will appear with video to watch. m.youtube.com/watch?v=sa+2DFdfd .. but how ?

search notes:

When I try this on my iphone 5 using safari I see the navigation bar changes perfectly according to which page I am in. in this example I see; m.youtube.com/watch?v=34124S on safari but I can not cacth it on uiwebview.... I can not get the latest loaded web page link.

ShouldLoadStart does only work only for the first time page loaded. Then when you click on the page; if the link is type of <a href='/someLink' /> link the ShouldLoadStart catches the link but if it is a made of javascript type of link , the clicked link is not caught by delegates. Please help to catch m.youtube.com/watch?v=34124S like safari does on youtube pages.

2
  • Hi @theklc, i have same problem, did you find any solution yet?
    – ZAFAR007
    Sep 1, 2016 at 19:33
  • @ZAFAR007 I got the link by using central notification. when the video appears full view, I catch that event and I get the loaded pages inner html and get the unique link.. If you have better idea please share below! Oct 17, 2016 at 8:55

4 Answers 4

2

If you want to store the url this will do:

NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"window.location"];

or

currentURL = currentWebView.request.URL.absoluteString;

Try above two in

-(void)webViewDidFinishLoad:(UIWebView *)webView

Also this can be done:

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
  NSLog(@"%@",webView.request.mainDocumentURL);

 [_activityindicator stopAnimating];
}
1
  • I have tried it, but it did not work out, have you ever tried it ?may be am I missing something? thank you! Sep 9, 2013 at 11:23
0

implement this in your webview delegate class

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType 
{
    //CAPTURE USER LINK-CLICK.
    NSURL *url = [request URL];
    NSLog(@"clicked url: %@",[url absoluteString]);

    return YES;
}
1
  • 2
    this is only called when I load the page url for the first time. But when I click on a link of a m.youtube.com page, this delegate does not catch the link. Sep 9, 2013 at 6:50
0

I got the link by using central notification. when the video appears full view, I catch that event and I get the loaded pages inner html and get the unique link..

If you have better idea please share below!

0
0

I had the same issue. If it is the case you can use WKWebView.

For UIWebView the only solution I found is to get current URL via javascript:

    [webView stringByEvaluatingJavaScriptFromString: @"location.href"];

The next issue is that shouldStartLoadWithRequest is not triggered. To solve it you can override requests with NSURLProtocol (btw it's not possible with WKWebView). Or just check current URL every second by timer :)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.