ios - 在 iOS 中打开 PDF 阅读器的 PDF 链接

标签 ios objective-c pdf uiwebview

我正在从我的 WebView 中获取 PDF 文件链接。当我单击该链接时,我想在我的 iBook 应用程序中打开该 PDF 文件。

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

enter image description here

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

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

当编译器进入 else 部分时,我得到了一个错误。我显示了那个错误:

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.

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

最佳答案

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

如果您的意图是让用户阅读 pdf 文件,则将请求的处理留给 webview 本身(取出 -webView: shouldStartLoadWithRequest: 委托(delegate)方法) 或者,如果您想显示 ios 设备可以对文件执行的其他一些选项(打印、预览、邮件等),那么您必须将该 pdf 文件下载到本地,然后将 UIDocumentInteractionController 对象的 url 属性设置为本地路径 url演示前已保存文件。

关于ios - 在 iOS 中打开 PDF 阅读器的 PDF 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21179175/

相关文章:

android - flutter中实现自定义底部导航栏

ios - 合并/合并两个图像时,iPad 应用程序因内存警告而崩溃

ios - 如何从 UITabBarItem 获取 RootViewController

ios - 如何在 Objective-C 中将 IP 地址从 NSString 转换为 unsigned int?

pdf - 如何在iOS11的PDFKit中添加图片标注

ios - GPX 文件不加载 iOS Xcode

objective-c - 导出带有淡入淡出音频的 QTMovie 的最佳方式

ios - 删除 Testflight 后构建失败

batch-file - Windows 10 从命令行打印为 PDF

javascript - PDF jQuery 翻书插件