检查UIWebview是否显示PDF

检查UIWebview是否显示PDF

本文介绍了检查UIWebview是否显示PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要说清楚,我的问题是询问如何在UIWebview中显示PDF。我想检查用户是否从某个网站或链接导航到PDF(.pdf)文档。这样我就可以向用户显示更多选项,例如保存PDF或打印它。检查UIWebView内容是否为PDF的最佳方法是什么?

To be clear, my question is not asking how to display a PDF in a UIWebview. I want to check if the user has navigated to a PDF (.pdf) document from some website or link. That way I can show more options to the user, like saving the PDF or printing it. What's the best way to check if the UIWebView's content is a PDF?

推荐答案

您也可以检查MIME类型更长的旅程:

You can check the MIME type too, for a slightly longer journey:

@property (nonatomic, strong) NSString *mime;

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
   mime = [response MIMEType];
}

- (BOOL)isDisplayingPDF {
    NSString *extension = [[mime substringFromIndex:([mime length] - 3)] lowercaseString];

    return ([[[self.webView.request.URL pathExtension] lowercaseString] isEqualToString:@"pdf"] || [extension isEqualToString:@"pdf"]);
}

这篇关于检查UIWebview是否显示PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 04:20