Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS中打开指向PDF阅读器的PDF链接_Ios_Objective C_Pdf_Uiwebview - Fatal编程技术网

在iOS中打开指向PDF阅读器的PDF链接

在iOS中打开指向PDF阅读器的PDF链接,ios,objective-c,pdf,uiwebview,Ios,Objective C,Pdf,Uiwebview,我正在从我的web视图中获取PDF文件链接。当我点击那个链接时,我想在我的iBook应用程序中打开那个PDF文件 我从服务器上得到了内容。我在UIWebview中显示了这样的内容 在此内容中有一个PDF链接“房地产新兴趋势”。当我选择此链接时,我想在iPhone pdf阅读器应用程序(如iBook、Adobe reader)中打开此pdf文件。当我单击此链接时,它将转到webView委托方法 -(BOOL)webView:(UIWebView*)webView shouldStartLoadW

我正在从我的web视图中获取PDF文件链接。当我点击那个链接时,我想在我的iBook应用程序中打开那个PDF文件

我从服务器上得到了内容。我在UIWebview中显示了这样的内容

在此内容中有一个PDF链接“房地产新兴趋势”。当我选择此链接时,我想在iPhone pdf阅读器应用程序(如iBook、Adobe reader)中打开此pdf文件。当我单击此链接时,它将转到webView委托方法

-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL* url = [request URL];
    NSLog(@"PDF URL : %@",url);
       if (UIWebViewNavigationTypeLinkClicked == navigationType)
    {
        if ([url isEqual:@"about:blank"])
        {
            return YES;
        }
        else
        {

            // Initialize Document Interaction Controller
            documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
            // Configure Document Interaction Controller
            documentInteractionController.delegate = self;
            // Present Open In Menu
            [documentInteractionController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES];

        }
    }
    return YES;
}
当编译器转到其他部分时,我遇到了一个错误。我显示了该错误:

PDF URL : http://www.uli.org/wp-content/uploads/ULI-Documents/Emerging-Trends-in-Real-Estate-Americas-2014.pdf
2014-01-17 16:44:49.233 ULINewYork[3163:a0b] *** Assertion failure in -[UIDocumentInteractionController setURL:], /SourceCache/UIKit_Sim/UIKit-2903.23/UIDocumentInteractionController.m:1010
2014-01-17 16:44:49.234 ULINewYork[3163:a0b] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener: delegate: <NSInternalInconsistencyException> UIDocumentInteractionController: invalid scheme http.  Only the file scheme is supported.
PDF网址:http://www.uli.org/wp-content/uploads/ULI-Documents/Emerging-Trends-in-Real-Estate-Americas-2014.pdf
2014-01-17 16:44:49.233 UlinewyWork[3163:a0b]***在-[UIDocumentInteractionController setURL:],/SourceCache/UIKit_Sim/UIKit-2903.23/UIDocumentInteractionController.m:1010中断言失败
2014-01-17 16:44:49.234 UlinewyWork[3163:a0b]***WebKit在webView中丢弃了一个未捕获的异常:decidePolicyForNewWindowAction:请求:newFrameName:decisionListener:委托:UIDocumentInteractionController:无效的方案http。仅支持文件方案。

请给我一些处理这个过程的想法。

在苹果文档的帮助下,我尝试了与您相同的方法。我得到了与您提到的相同的错误,然后我下载了应用程序以了解
UIDocumentInteractionController
,在该应用程序中,他们使用此类打开位于本地应用程序沙箱中的文件或位于主捆绑包中的文件

如果您的目的是让用户阅读pdf文件,则将请求的处理留给webview本身(去掉-webview:shouldStartLoadWithRequest:delegate方法)
或者,如果您想显示ios设备可以执行的其他选项(打印、预览、邮件等)对于该文件,您必须将该pdf文件下载到本地,然后将UIDocumentInteractionController对象的url属性设置为您在呈现之前保存该文件的本地路径url。

可能重复的@Sabs您是否能够实现此功能?现在已经是第35年了,\“onclick=\”javascript:\u gaq.push([''u trackEvent','download',');\“target=”_blank\“>onclick=”javascript的新兴趋势:“\u gaq.push”([u trackEvent','download',”);“target=”“\u blank\”>房地产是房地产和土地使用行业最受推崇的年度行业展望之一。

”@Sabs我在下面的问题中发现了同样的问题,也许它会帮助你