2
我想获得在UIWebView中加载的文件的MIME类型,以便我可以将它们下载到我现在有的方法工作一些时间,有无论如何我可以做它更好?获取在UIWebView中加载的文件的MIME类型
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *main = url.absoluteString;
//enter code here currentURL = main;
NSURLRequest *req = [NSURLRequest requestWithURL:url];
NSURLConnection *conn = [NSURLConnection connectionWithRequest:req delegate:self];
[conn start];
return YES;
}
NSString *mime = [response MIMEType];
NSLog(@"%@",mime);
DownloadManagerAppDelegate *delegate = (DownloadManagerAppDelegate *)[[UIApplication sharedApplication] delegate];
DLMan *downloadView = [[DLMan alloc] init];
if ([mime rangeOfString:@"application/x-compressed"].length>0 || [mime rangeOfString:@"application/x-zip-compressed"].length>0 || [mime rangeOfString:@"application/zip"].length>0 || [mime rangeOfString:@"multipart/x-zip"].length>0)
{
self.tabBarController.selectedIndex = 1;
[[delegate myDownloadManager]addDownload:currentURL];
NSLog(currentURL);
NSLog(@"download");
}
我试过你的第一个例子,你的第二个不会工作,因为我试图从filehosts下载,他们有时会在url中包含.zip或.mp3,然后才能下载它 – Heli0s 2011-04-26 05:21:53