我在我的应用程序中使用PHAsset,我需要将图像和视频上传到api,因为我需要mime类型的图像和视频。在iOS的早期版本中,我使用了以下代码,但在iOS 8中,我不知道如何获取mimetype我尝试过查看苹果PHAsset编程指南但无法找到它。
ALAssetRepresentation *representation = [asset defaultRepresentation];
NSString *mimeType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass
((__bridge CFStringRef)[representation UTI], kUTTagClassMIMEType);
寻找任何指导。
答案 0 :(得分:1)
PHContentEditingInput
拥有财产uniformTypeIdentifier
。您可以在the documentation找到更多信息。
@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);
}];
答案 1 :(得分:1)
您还可以从PHContentEditingInput类中找到uniformTypeIdentifier。为了这;使用PHAsset的requestContentEditingInput函数
别忘了导入MobileCoreServices
示例Swift 3.1代码:
import MobileCoreServices
let options = PHContentEditingInputRequestOptions()
options.isNetworkAccessAllowed = true //for icloud backup assets
let asset : PHAsset = ..... //sampleAsset
asset.requestContentEditingInput(with: options) { (contentEditingInput, info) in
if let uniformTypeIdentifier = contentEditingInput?.uniformTypeIdentifier {
//check type here
if uniformTypeIdentifier == (kUTTypeGIF as String) {
debugPrint("This asset is a GIF")
}
}
}
答案 2 :(得分:0)
使用PHImageManager的requestImageDataForAsset方法。在它的resultBlock中,该方法返回资产的UTI-Type。
答案 3 :(得分:0)
我最终获得了PHAsset的MIME类型,如下所示(iOS 9 +):
1 is divided by 1
2 is divided by 1
2 is divided by 2
3 is divided by 1
3 is divided by 3
4 is divided by 1
4 is divided by 2
4 is divided by 4
5 is divided by 1
5 is divided by 5
6 is divided by 1
6 is divided by 2
6 is divided by 3
6 is divided by 6
7 is divided by 1
7 is divided by 7
8 is divided by 1
8 is divided by 2
8 is divided by 4
8 is divided by 8
9 is divided by 1
9 is divided by 3
9 is divided by 9
将事物与呼唤相结合/加以改进:
如果有人对#2或#3有见识,将不胜感激。当我发现更多信息时,我会更新我的答案。