iOS - 检查 webView 是否在非'pdf' 上加载了 PDF 内容;文件扩展名 [英] iOS - Check if webView is loaded with PDF content on non-'pdf' file extension

查看:27
本文介绍了iOS - 检查 webView 是否在非'pdf' 上加载了 PDF 内容;文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查(布尔值)是否在 UIWebView 中加载了 PDF 内容.这个问题已经存在,但不是这种情况.

I would like to Check (boolean value) if PDF content is loaded in the UIWebView. This question already exists, but not this case.

这并不只是检查 webView Url 的路径扩展那么简单,因为这个 PDF 内容是通过 ASPX 生成的.扩展将返回aspx".也不只是在 url 中查找,自从我请求 PDF 文件以来,字符串 'pdf' 将始终在 url 中找到.我需要检查服务器是否真的按原样返回了 PDF 文件.

It's not as simple as just checking the path extension of the webView Url because this PDF content is generated via ASPX. The extension will return 'aspx'. Also not just looking in the url, the string 'pdf' will always be found in the url since I requesting a PDF file. I need to check if the server really returns a PDF file as it should.

好的,webView 加载了 PDF 内容,但没有加载到服务器上的特定 pdf 文件.(也许是 apache 重定向、aspx pdf 生成或其他东西)

Ok, The webView is loaded with PDF content but not to a specific pdf file on the server. (maybe apache redirect,aspx pdf generation or just something else)

如果在 Safari 应用程序中加载了这个 url(到 aspx 文件),它会检测到这个 PDF 内容(即使是 aspx 文件).上面写着在……中打开"等等.

If this url is loaded in the Safari Application (to the aspx file), it will detect this PDF content (even if aspx file). It says "open in..." and so on.

如何检测 UIWebView 是否加载了非 pdf 扩展文件上的 PDF 内容?

How to detect if the UIWebView is loaded with PDF content on non-pdf extention file?

乔纳森

推荐答案

我用这个解决了:

谢谢@Guilherme

Thanks @Guilherme

-(bool)isPDFContentLoadedInWebView:(UIWebView *)webView {
    NSString *mime =[[NSURLCache sharedURLCache] cachedResponseForRequest:webView.request].response.MIMEType;
    if (!([mime rangeOfString:@"pdf"].location == 0)) {
    return YES;
    } else {
        return NO;
    }

    return NO;
}

这篇关于iOS - 检查 webView 是否在非'pdf' 上加载了 PDF 内容;文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆