UIWebView Delegate get MIME Type

拜拜、爱过 提交于 2019-12-03 04:37:25

Just use js

let contentType = webView.stringByEvaluatingJavaScript(from: "document.contentType;")
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {

    NSURL *url = request.URL;
    NSURLRequest *req  = [NSURLRequest requestWithURL:url];
    NSURLConnection *conn = [NSURLConnection connectionWithRequest:req delegate:self];
    [conn start];
    return YES;
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{

    NSString *mime = [response MIMEType];
    NSLog(@"%@",mime);

}

You could try subclassing NSURLProtocol and handling the response information parsing there.

Look at

- (void)URLProtocol:(NSURLProtocol *)protocol didReceiveResponse:(NSURLResponse *)response cacheStoragePolicy:(NSURLCacheStoragePolicy)policy

Don't forget to about subresources also using these hooks.

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