我正在尝试使用此代码获取所选图像的文件名称:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
img = [info objectForKey:UIImagePickerControllerOriginalImage];
[self.imgFoto setImage:img];
NSURL *imagePath = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
NSString *imageName = [imagePath lastPathComponent];
NSLog(@"image name is %@", imageName);
[self dismissViewControllerAnimated:YES completion:NULL];
}
但我所看到的只是:
我的意思是,我不应该像IMG_00001.jpeg
,IMG_00002.jpeg
等?
问候。
答案 0 :(得分:1)
使用AssetsLibrary作为以下代码行
#import <AssetsLibrary/AssetsLibrary.h>
比
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
{
ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
NSLog(@"[imageRep filename] : %@", [imageRep filename]);
};
// get the asset library and fetch the asset based on the ref url
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];