I am using the Page View Application to show a series of PDF's. The UIWebView is displaying the PDF's fine, however whenever there is a link that is embedded into the PDF and the user clicks it, it opens the link inside of the UIWebView. I want it to open said link in safari.
NSString *path = [[NSBundle mainBundle] pathForResource:page ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[self.webView loadRequest:request];
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
正如您所看到的,我已尝试插入代码以启动它,但BOOL在步进时永远不会运行。
答案 0 :(得分:0)
使用此: -
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked || inType ==UIWebViewNavigationTypeOther) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
如果用户点击样式链接,则会发生UIWebViewNavigationTypeLinkClicked,如果更改是在Javascript中完成的(例如onclick事件),则使用UIWebViewNavigationTypeOther。
此外,如果您首次加载页面,或者您要通过元刷新或其他方式重定向,则使用UIWebViewNavigationTypeOther