LaunchServices:错误:URL方案applewebdata没有注册处理程序

时间:2016-02-10 18:18:17

标签: ios objective-c

我有一个代码可以在Safari中的webview中打开一个链接,看起来像这样。

- (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;

}

但是,当我点击该链接时,会显示错误

  

LaunchServices:错误:URL方案applewebdata

没有注册处理程序

环境是iOS 9.我需要更改plist中的某些设置吗?

1 个答案:

答案 0 :(得分:0)

以下是我解决问题的方法:

- (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;
}

只需操作URL字符串就可以没有applewebdata,只需简单的URL格式就可以了。