Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where's the iPhone MIME type database?

I have a program for the iPhone that is supposed to be doing intelligent things (picking out appropriate icons for file types) given a list of filenames. I'm looking for the iPhone take on something like /etc/mime.types or something similar- an API call is what I'm assuming would be available for the phone. Does this exist?

like image 752
Matt Erickson Avatar asked Mar 13 '10 16:03

Matt Erickson


People also ask

Where is MIME type stored?

All MIME type information is stored in a database. The MIME database is located in the directory /usr/share/mime/ . The MIME database contains a large number of common MIME types, stored in the file /usr/share/mime/packages/freedesktop.

Where is MIME type defined?

A MIME type (now properly called "media type", but also sometimes "content type") is a string sent along with a file indicating the type of the file (describing the content format, for example, a sound file might be labeled audio/ogg , or an image file image/png ).

What is MIME database?

The MIME database contains file content sniffer information. The file content sniffer information provides details of a specific pattern in the file. The MIME database associates this pattern with a MIME type. The application checks the file for the pattern.


2 Answers

If it did, your app surely wouldn't have permissions to even read it directly. What are you trying to do?

EDIT

This is a function I wrote a while ago. I wrote it for the Mac, but it looks like the same functions exist on the iPhone. Basically, you give it a filename, and it uses the path extension to return the file's MIME type:

#import <MobileCoreServices/MobileCoreServices.h>
...
- (NSString*) fileMIMEType:(NSString*) file {
    CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)[file pathExtension], NULL);
    CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass (UTI, kUTTagClassMIMEType);
    CFRelease(UTI);
    return [(NSString *)MIMEType autorelease];
}
like image 161
Dave DeLong Avatar answered Sep 18 '22 13:09

Dave DeLong


The following function will return the mime-type for a given file extension in Swift 2

import MobileCoreServices

func mimeTypeFromFileExtension(fileExtension: String) -> String? {
    guard let uti: CFString = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension as NSString, nil)?.takeRetainedValue() else {
        return nil
    }

    guard let mimeType: CFString = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() else {
        return nil
    }

    return mimeType as String
}
like image 21
dreamlab Avatar answered Sep 20 '22 13:09

dreamlab