如何检测UIWebView中显示的本地pdf中的超链接

时间:2013-02-11 09:13:31

标签: ios objective-c uiwebview datadetectortypes

我使用以下代码在UIWebView中加载pdf文件:

NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@", pdfString] ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webview loadRequest:req];

它工作正常。但是我想在pdf文件中启用超链接(就像UITextView检测链接一样)。

1 个答案:

答案 0 :(得分:1)

使用此:

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType 
{
    if ( inType == UIWebViewNavigationTypeLinkClicked ) {
        [[UIApplication sharedApplication] openURL:[inRequest URL]];
        return NO;
    }
    return YES;
}