本文介绍了如何使用PHAsset在iOS 8中获取图像或视频的MIME类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用PHAsset,我需要将图像和视频上传到api,因为我需要mime类型的图像和视频。在iOS的早期版本中,我使用以下代码但在iOS 8中我不知道如何获取mimetype我已经尝试查看苹果PHAsset编程指南但无法找到它。

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);

寻找任何指导。

推荐答案

PHContentEditingInput 有属性 uniformTypeIdentifier 。您可以在。

@import MobileCoreServices.UTType;

...

PHAsset *asset = ...
PHContentEditingInputRequestOptions *options = ...
[asset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
    NSString *MIME = (__bridge NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)contentEditingInput.uniformTypeIdentifier, kUTTagClassMIMEType);
}];

这篇关于如何使用PHAsset在iOS 8中获取图像或视频的MIME类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 00:22