Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 获取UIWebView中加载的文件的mimetype_Iphone_Ios4_Uiwebview_Download_Mime Types - Fatal编程技术网

Iphone 获取UIWebView中加载的文件的mimetype

Iphone 获取UIWebView中加载的文件的mimetype,iphone,ios4,uiwebview,download,mime-types,Iphone,Ios4,Uiwebview,Download,Mime Types,我正在尝试将MIME类型的文件加载到UIWebView中,这样我就可以下载它们。我现在使用的方法在某些情况下是有效的,有没有更好的方法 - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { NSURL *url = request.URL; NSS

我正在尝试将MIME类型的文件加载到UIWebView中,这样我就可以下载它们。我现在使用的方法在某些情况下是有效的,有没有更好的方法

- (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");
}

NSURLConnection
delegate
didReceiverResponse
中,使用如下内容:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{
   NSString *mime = [response MIMEType];
}

正如我所读到的,您没有正确获得MIME,您可能对另一种方法感兴趣,创建MIME类型的
plist
,例如mimeTypes.plist

(不一定是所有类型,至少是要处理的类型)

使用以下方法将它们加载到
n目录中

NSString *mainBundlePath = [[NSBundle mainBundle] bundlePath];
NSString *plistPath = [mainBundlePath stringByAppendingPathComponent:@"mimeTypes.plist"];

NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:plistPath]
通过搜索目标的扩展名来检查MIME:

[dict valueForKey:@"mp3"];  // will return audio/mpeg.

请检查此链接以查看列表。

我已经尝试了您的第一个示例,但您的第二个示例无效,因为我正在尝试从filehosts下载,而且在您下载之前,url中有时会包含.zip或.mp3