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

查看:104
本文介绍了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".同样,不仅要查看网址,因为自我请求PDF文件以来,字符串"pdf"总会在网址中找到.我需要检查服务器是否确实返回了应有的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)

如果此url已加载到Safari应用程序中(到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?

乔纳森

推荐答案

我使用以下方法解决了该问题:

I solved it using this:

感谢@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天全站免登陆