I am using PHAsset in my application where I need to upload image and video to api, for that I need mime type of image and video. In previous version of iOS I was using following code but in iOS 8 I don't know how to get mimetype I have tried looking into apple PHAsset programming guide but unable to find it.
ALAssetRepresentation *representation = [asset defaultRepresentation];
NSString *mimeType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass
((__bridge CFStringRef)[representation UTI], kUTTagClassMIMEType);
Looking for any guidance.
Use the requestImageDataForAsset method of PHImageManager. In it's resultBlock the method returns the UTI-Type for the asset.
I ended up getting the MIME type for a PHAsset as follows (iOS 9+):
Couple things to call out/ways to improve:
If anyone has insight on #2 or #3, it would be greatly appreciated. I'll update my answer when I find out more.
PHContentEditingInput
has propertyuniformTypeIdentifier
. You can find more in the documentation.Also you can find uniformTypeIdentifier from PHContentEditingInput class. For this; use requestContentEditingInput function from PHAsset
Don't forget to import MobileCoreServices
Sample Swift 3.1 code: