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