如何在 xcode 中将 mimetype 转换为文件扩展名
例如我有这个代码
File Extension MIME Type
aifc audio/x-aiff
avi video/x-msvideo
gz application/x-gzip
jpg image/jpeg
Xcode
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSString *mime = [response MIMEType];
NSString *extension = @"" // how to covert it ?!
}
最佳答案
包括 <MobileCoreServices/MobileCoreServices.h>
或 <CoreServices/CoreServices.h>
然后只需以下代码:
CFStringRef mimeType = (CFStringRef)@"audio/x-aiff";
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeType, NULL);
CFStringRef extension = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension);
关于xcode - 将 mimetype 转换为文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24678971/