ios - 如何使用 UIDocumentPickerViewController 获取原始文件名?
问题描述
我需要知道要导入的文件类型。我可以从文件名中找出类型
对于 PHAsset,您可以使用以下方法:
Attachment *attachment = [[Attachment alloc] init];
attachment.assetIdentifierInternal = asset.localIdentifier;
attachment.descriptionInfo = [[NSProcessInfo processInfo] globallyUniqueString];
attachment.isPhoto = YES;
attachment.isDocument = NO;
NSArray *resources = [PHAssetResource assetResourcesForAsset:asset];
NSString *fileName = ((PHAssetResource *)resources[0]).originalFilename;
attachment.format = [fileName pathExtension];
DocumentPicker 有类似的东西吗?
descriptInfo 显示没有问题。名称 - 无。
名称设置器:
- (void)setName:(NSString *)name {
_name = name;
self.format = [name pathExtension];
CFStringRef fileExtension = (__bridge CFStringRef) self.format;
CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
self.isPhoto = UTTypeConformsTo(fileUTI, kUTTypeImage);
self.isDocument = UTTypeConformsTo(fileUTI, kUTTypeData); }
解决方案
经过一番搜索,我自己找到了解决方案。名称和格式很容易通过 URL 跟踪。像这样
attachment.fileUrlInternal = url;
attachment.format = [attachment.fileUrlInternal pathExtension];
attachment.name = url.lastPathComponent;
推荐阅读
- r - 在 R 中获取未来 Worldclim 数据
- c++ - 稳定级联阴影映射中的光视图矩阵
- ruby - 使用块时 do..end 和 {} 之间的区别
- r - 如何在 R 中查询 Neo4j 关系?
- sql-server - 如何使用 SELECT 语句中的可用值更新表
- python - 如何将剩余字符串“34defg”添加到输出python
- javascript - 在渲染我的应用程序时,如何将不同的反应片段放在一起以避免“元素类型无效错误”?
- excel - 在excel vba中循环多个值
- kotlin - 如何在许多字符串中找到为空或 null 的字符串并使代码看起来干净
- javascript - 不确定为什么图标旋转功能部分工作 Javascript