4

我正在尝试使用 iOS 8 中的新照片 API 获取照片的文件扩展名,但直到现在还没有找到这样做的方法。在 iOS 8.0 之前,我会使用 ALAssetRepresentation 来获取文件扩展名,例如:

// Get asset representation from asset
ALAssetRepresentation *assetRepresentation = [asset defaultRepresentation];

// Extract file extension from the original file name
NSString* fileExt = [[assetRepresentation filename] pathExtension];

现在有什么方法可以获取照片的文件扩展名吗?PS:我正在使用新的照片 API,因为我需要访问我的照片应用程序中的所有照片,而 ALassetsLibrary 只允许访问“最近添加”的照片。

4

4 回答 4

12

我懂了。

[[PHImageManager defaultManager] requestImageDataForAsset:asset options:imageRequestOptions resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {

        NSLog(@"info - %@", info);
    }];

PHImageFileDataKey = <PLXPCShMemData: 0x179ab6d0> bufferLength=1384448 dataLength=1384448;
PHImageFileOrientationKey = 1;
PHImageFileSandboxExtensionTokenKey = "c05e608acaf0bb212086ed2d512ccc97ea720ac3;00000000;00000000;0000001a;com.apple.app-sandbox.read;00000001;01000003;0000000000030b8c;/private/var/mobile/Media/DCIM/102APPLE/IMG_2607.JPG";
PHImageFileURLKey = "file:///var/mobile/Media/DCIM/102APPLE/IMG_2607.JPG";
PHImageFileUTIKey = "public.jpeg";
PHImageResultDeliveredImageFormatKey = 9999;
PHImageResultIsDegradedKey = 0;
PHImageResultIsInCloudKey = 0;
PHImageResultIsPlaceholderKey = 0;
PHImageResultWantedImageFormatKey = 9999;
于 2014-09-24T08:21:49.807 回答
2

这是一种方法:

PHImageRequestOptions * imageRequestOptions = [[PHImageRequestOptions alloc] init];
imageRequestOptions.synchronous = YES;

[[PHImageManager defaultManager]
 requestImageForAsset:asset
 targetSize:CGSizeMake(2048, 2048)
 contentMode:PHImageContentModeAspectFit
 options:imageRequestOptions
 resultHandler:^(UIImage *result, NSDictionary *info) {
 }];

文件名包含在 info. 例如:

PHImageFileURLKey = "file:///var/mobile/Media/DCIM/100APPLE/IMG_0066.JPG";
于 2014-09-20T03:45:32.593 回答
0

**imageManager.requestImageDataForAsset((images[indexPath.row] as PHAsset), options:PHImageRequestOptions(), resultHandler: {imagedata,dataUTI,Orientation,info in

var str:String=((((info as Dictionary)["PHImageFileURLKey"])! as NSURL).lastPathComponent as String) cell.imageName.text=str as String**

于 2014-12-31T16:35:35.277 回答
0

These is also once simple way to get original file name selected from photos

PHAsset *asset; // Init this object with your PHAsset object 

//and then use below line 
NSLog(@"asset ext : %@",[[asset valueForKey:@"filename"] pathExtension]);
于 2016-10-03T11:02:17.837 回答