[英]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;
}
正如你可以看到我試圖插入代碼來啟動它,但BOOL永遠不會在步進時運行。
用這個:-
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked || inType ==UIWebViewNavigationTypeOther) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
如果用戶點擊樣式鏈接,並且在Javascript(例如onclick事件)中完成更改,則使用UIWebViewNavigationTypeOther,則發生UIWebViewNavigationTypeLinkClicked。
此外,如果您首次加載頁面,或者您將通過元刷新或某些內容重定向,則使用UIWebViewNavigationTypeOther
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.