gpt4 book ai didi

ios - 如何使用UIDocumentPickerViewController获得原始文件名?

转载 作者:行者123 更新时间:2023-12-01 16:14:05 24 4
gpt4 key购买 nike

我需要知道要导入的文件类型。
我可以从文件名中找到类型

对于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;

关于ios - 如何使用UIDocumentPickerViewController获得原始文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53047474/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com