通过发送一个基于本地文件的URL请求,从响应对象中获取MIMEType值。代码如下:
NSString *path = [[NSBundle mainBundle] pathForResource:@"测试文件"
ofType:@"pdf"];
//创建本地文件URL
NSURL *url = [NSURL fileURLWithPath:path];
//创建请求对象
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//发送请求
NSHTTPURLResponse *response = nil;
[NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:nil];
//获取MIMIType
NSString *mimeType = response.MIMEType;