How to retrieve photo extension (jpg/png) in iOS 8.0 using Photos API?

眉间皱痕 提交于 2019-12-04 10:09:03

I've got it.

[[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;

Here is one way to do it:

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) {
 }];

The file name is contained in info. For example:

PHImageFileURLKey = "file:///var/mobile/Media/DCIM/100APPLE/IMG_0066.JPG";

**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**

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!