0
votes

I have a code that opens a link inside a webview in Safari, which looks like this.

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{


    if (navigationType == UIWebViewNavigationTypeLinkClicked){
        NSLog(@"%@", request);
        NSURL *url = request.URL;
        [[UIApplication sharedApplication] openURL:url];
    }

    return YES;

}

However, when I click the link, it shows the error

LaunchServices: ERROR: There is no registered handler for URL scheme applewebdata

The environment is iOS 9. Is there some setting in the plist I need to change?

1
Had a similar problem, in my case it was that the URL involved was missing "http://" at the beginning. - alasker

1 Answers

0
votes

Here's how I fixed the issue:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{


if (navigationType == UIWebViewNavigationTypeLinkClicked){

    NSString *requestURLString =  request.URL.absoluteString;
    NSString *trimmedRequestURLString = [requestURLString stringByReplacingOccurrencesOfString:@"^(?:applewebdata://[0-9A-Z-]*/?)" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, requestURLString.length)];

    trimmedRequestURLString = [trimmedRequestURLString stringByReplacingOccurrencesOfString:@"%22" withString:@""];

    NSLog(@"%@", trimmedRequestURLString);
    NSURL *url = [NSURL URLWithString:trimmedRequestURLString];
    NSLog(@"%@", url);
    [[UIApplication sharedApplication] openURL:url];
}

return YES;
}

Just manipulating the URL string to have no applewebdata and just plain URL format worked.