UIWebview failed for URL error

Discussion in 'iOS Programming' started by erdinc27, Jul 18, 2016.

  1. erdinc27, Jul 18, 2016
    Last edited: Jul 18, 2016

    erdinc27 macrumors regular

    Jul 20, 2011
    I want to listen the webview and do something with the opened url. I do this with this delegate method.

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
        NSString *currentLink = request.URL.absoluteString;
        if ([currentLink containsString:@"close"]) {      
            [self closeTheAdvView];
        return YES;
    1- i try to click a button inside the webview. It works in iOS9 but not in iOS8. How can i make it clickable in iOS 8 as well ?

    2- when i click a button inside the webview it opens a new url(e.g:close.com). when i get that link then i will hide the webview. but when i click the button then it gives an error in log screen like
    what can be wrong here ?
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    I don't see any call to canOpenURL: in the code you show. You should probably return NO if you don't want this 'close' link to be opened. 'close.com' is not a URL. 'http://www.close.com' is a URL. Usually this kind of thing is done with custom schemes. 'close://me' is a valid URL that your code can scan for in the delegate callback.

    The error shows the empty string as the URL, which of course it cannot open. I don't know how that happens though.

Share This Page