要说清楚,我的问题是不询问如何在UIWebview中显示PDF。我想检查用户是否从某个网站或链接导航到PDF(.pdf)文档。这样我就可以向用户显示更多选项,例如保存PDF或打印它。检查UIWebView内容是否为PDF的最佳方法是什么?
答案 0 :(得分:5)
您也可以检查MIME类型,以获得稍长的旅程:
@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"]);
}
答案 1 :(得分:0)
这是一次漫长的旅行,但我认为这会奏效......
BOOL isPdf = [[[self.webView.request.URL pathExtension] lowercaseString]
isEqualToString:@"pdf"];