我正在尝试获取使用此代码选择的图像的文件名:
- (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
等等?
问候。
最佳答案
按以下代码行使用 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];
关于ios - 如何获取所选图像的 'file' 的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21613690/