简体   繁体   English

如何从UIWebView ios中显示的pdf加载safari中的链接

[英]How to load a link in safari from a pdf being displayed in a UIWebView ios

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

As You can see i have tried to insert the code to launch it but the BOOL never gets run when stepped through. 正如你可以看到我试图插入代码来启动它,但BOOL永远不会在步进时运行。

Use This:- 用这个:-

-(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 happens if the user taps a style link, if the change is done from within Javascript (onclick event for example) UIWebViewNavigationTypeOther is used. 如果用户点击样式链接,并且在Javascript(例如onclick事件)中完成更改,则使用UIWebViewNavigationTypeOther,则发生UIWebViewNavigationTypeLinkClicked。

Furthermore UIWebViewNavigationTypeOther is used if you first load a page or you'll be redirected by a meta refresh or something 此外,如果您首次加载页面,或者您将通过元刷新或某些内容重定向,则使用UIWebViewNavigationTypeOther

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM