iOS - Check if webView is loaded with PDF content on non-'pdf' file extension

Deadly 提交于 2020-01-15 10:58:07

问题


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

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.

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)

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.

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

Jonathan


回答1:


I solved it using this:

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


来源:https://stackoverflow.com/questions/21856923/ios-check-if-webview-is-loaded-with-pdf-content-on-non-pdf-file-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!