Reputation: 12051
I have a WebView with a PDF file and a document in it contains hyperlinks that I want to disable. I tried using this approach but it didn't work, the links still open and load the nasty URLS:
- I put
UIWebViewDelegate
in myViewController.h
- I then put this code in my
ViewController.m
:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (webView == myReadingArticlesWebView) {
return NO;
}
else {
return YES;
}
}
Any ideas how to make this simple and easy to work? I admit that I could make some mistakes in the process I described above.
EDIT:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([request.URL isFileReferenceURL]) {
return YES;
} else {
return NO;
}
}
The code above does nothing for me as well
Upvotes: 2
Views: 1683
Reputation: 37581
If as trumpetlicks says the PDF viewer ignores what you say from shouldStartLoadWithRequest, and if you don't want to disable ALL links (which setting the datadetectors would do).
Then something else you could try is creating a class derived from NSURLProtocol and registering it in your app delegate. This would be able to intercept the network traffic originating from the pdf and give you the chance to filter links and stop ones you don't want going out.
Upvotes: 0
Reputation: 7065
Based on all the comments back and forth!!!
So now what you need to do is rather than simply returning NO in your
shouldStartLoadWithRequest
method, you need to answer YES if the URL being loaded comes from local, and NO if it is coming from anywhere else. Use the
[request.URL isFileReferenceURL]
method to check if it is a local file. NOTE: this method apparently only works on iOS 5 and later, look at
Hopefully this does it for you :-)
Upvotes: 1
Reputation: 50697
Just set the UIWebView
's dataDetectorTypes
property to None:
[myReadingArticlesWebView setDataDetectorTypes:UIDataDetectorTypeNone];
Upvotes: 3