4

Is there a way how to get MIME type for ALAsset? There is a nice method for metadata:

NSDictionary *data = [[asset defaultRepresentation] metadata];

But that doesn't contain MIME type data...

Michal
  • 15,429
  • 10
  • 73
  • 104
  • As far as the documentation goes, the best we can do is get the asset type (photo/video/unknow). – n00bProgrammer Mar 12 '14 at 12:36
  • Right but what if Apple suddenly changes the way they store the images? Like...sure it is image/jpeg, because I know it's that way. But what if it changes? Isn't there more universal way? :( – Michal Mar 12 '14 at 12:39
  • 1
    Wait, I think I found it. – n00bProgrammer Mar 12 '14 at 12:40
  • http://stackoverflow.com/questions/5048640/retrieving-a-filename-for-an-alasset - I NSLogged the filename with last answer here (`ALAssetRepresentation`), and it say JPG/PNG for the images I selected. – n00bProgrammer Mar 12 '14 at 12:45
  • I know this does not give you a generic response, but this is the best I could salvage from the web. Sorry. – n00bProgrammer Mar 12 '14 at 12:47

1 Answers1

15
ALAssetRepresentation *rep = [asset defaultRepresentation];

NSString* MIMEType = (__bridge_transfer NSString*)UTTypeCopyPreferredTagWithClass
             ((__bridge CFStringRef)[rep UTI], kUTTagClassMIMEType);

This will give you the MIME type. You need to add MobileCoreService framework and import <MobileCoreServices/MobileCoreServices.h>

Boran
  • 949
  • 10
  • 17