xcode - 将 mimetype 转换为文件扩展名

标签 xcode nsurlconnection mime-types file-extension

如何在 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/

相关文章:

ios - 无法在 Xcode 9 中创建配置文件

iOS Swift : Initializer for conditional binding must have Optional type, 不是 '() -> 字符串?

iphone - 从 NSThread 函数调用时,不会调用 NSURLConnection 委托(delegate)

php - 使用 php 为所有文件格式查找 Mime 类型的文件或 url

tomcat - 如何为 Tomcat 6 中的任何文件扩展名设置默认 mime 类型?

objective-c - 手指在 iPad 屏幕上滑动

xcode - 如何处理未知的 UILabel 高度及其对 Interface Builder 下方标签的影响?

swift - 我是否必须关闭使用 NSURLSessionDataTask 创建的连接

objective-c - 使用来自异步 NSURLConnection 的数据填充 NSImage

javascript - 在 React 中将字符串下载为 .txt 文件