Skip to content

Instantly share code, notes, and snippets.

@quellish
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save quellish/14ad2315fc4a8cc2dabd to your computer and use it in GitHub Desktop.

Select an option

Save quellish/14ad2315fc4a8cc2dabd to your computer and use it in GitHub Desktop.
Method for getting an array of MIME types for images that ImageIO and UIKit can understand.
@import ImageIO;
@import MobileCoreServices;
+ (NSArray *) imageMIMETypes {
NSArray *result = nil;
NSMutableArray *mimeTypes = nil;
NSArray *typeIdentifiers = nil;
typeIdentifiers = (__bridge_transfer NSArray*)CGImageSourceCopyTypeIdentifiers();
mimeTypes = [[NSMutableArray alloc] init];
for (NSString *type in typeIdentifiers){
NSString *MIMETypeString = nil;
MIMETypeString = CFBridgingRelease(UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)type, kUTTagClassMIMEType));
if ([MIMETypeString length] > 0){
[mimeTypes addObject:MIMETypeString];
}
}
result = [mimeTypes copy];
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment