获取文件类型笔记

#import
-(NSString *)MIMEType
{

if (![[NSFileManager defaultManager] fileExistsAtPath:self]) {
    return nil;
}
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge  CFStringRef)[self pathExtension], NULL);
CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass (UTI, kUTTagClassMIMEType);
CFRelease(UTI);
if (!MIMEType) {
    return @"application/octet-stream";
}
return (__bridge NSString *)MIMEType;

}

-(NSString *)MIMEType
{

NSURLResponse *response = nil;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:self]];
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
return response.MIMEType;

}

你可能感兴趣的:(获取文件类型笔记)