how to convert mimetype to file extension in xcode for example i have this code
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 ?!
}
A media type (also known as a MIME type) is a two-part identifier for file formats and format contents transmitted on the Internet. The Internet Assigned Numbers Authority (IANA) is the official authority for the standardization and publication of these classifications.
The main MIME media type for PDF is application/pdf. This type is defined by RFC 8118 and is the responsibility of ISO TC 171 SC 2 WG 8. It was last updated in March 2017, prior to the original publication of PDF 2.0, so the PDF Association is proposing a minor refresh and update in the upcoming May 2022 ISO meetings.
Slightly longer answer: Mime types and file extensions provide hints to how to deal with a file. Whereas file extensions are commonly used for your OS to decide what program to open a file with, Mime types are used by your browser to decide how to present some data (or the server on how to interpret received data).
include <MobileCoreServices/MobileCoreServices.h>
or <CoreServices/CoreServices.h>
then just following code:
CFStringRef mimeType = (CFStringRef)@"audio/x-aiff";
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeType, NULL);
CFStringRef extension = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With