PHAsset获取原始文件名 [英] PHAsset get original file name

查看:1046
本文介绍了PHAsset获取原始文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有办法使用PHAsset获取原始文件名?

I wonder if there any way to get the original file name using PHAsset?

我使用以下代码提取文件信息。

I use the following code to extract the file info.

   [[PHImageManager defaultManager] requestImageDataForAsset:asset options:requestOption resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
    entity.fileUrl =  [info objectForKey:@"PHImageFileURLKey"];
    entity.filename = [[NSFileManager defaultManager] displayNameAtPath:[ entity.fileUrl path]];
   }];

但是,它不会返回原始名称,但名称格式为img_123
我刚检查了官方苹果文档。已经推出了一个新类 PHAssetResource 和属性 originalFilename ,它可以在iOS 9+中找到。问题是我使用了基于Photos框架的图像选择器库 CTAssetsPickerController ;它将拾取的图像作为 PHAsset 对象返回。 PS。我正在寻找与iOS 8兼容的解决方案:)。
谢谢!

However, It doesn't return original name but the name in the format "img_123" I've just checked official apple docs . there has been introduced a new class PHAssetResource and the property originalFilename which is available in the iOS 9+. The problem is that I use the image picker library CTAssetsPickerController which 's based on the Photos framework; it returns picked image as the PHAsset object . PS. I'm looking for the solution which is compatible with iOS 8 :). Thank you!

推荐答案

在iOS 8上,您的解决方案是获取文件名的正确方法(也是唯一的方法)所有。

On iOS 8 your solution is the right (and only approach) to get a filename at all.

在iOS 9上,这有效:

On iOS 9 this works:

NSArray *resources = [PHAssetResource assetResourcesForAsset:asset];
NSString *orgFilename = ((PHAssetResource*)resources[0]).originalFilename;

这篇关于PHAsset获取原始文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆