2014-02-06 19 views
0

我试图获得与此代码选择的图像的文件名:如何获得“文件名”的图像中选择

- (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]; 
} 

但所有我看到的是:

enter image description here

我的意思是,我不应该像IMG_00001.jpeg,IMG_00002.jpeg等?

问候。

+0

这是不相关的Xcode(的结果,如果你使用'emacs'和'使问题将是相同的'编写你的程序)。至于它“应该”是什么:如果它总是相同的,那么它总是一样的。这是一个实现细节,没有理由尝试假设它。 – 2014-02-06 20:49:18

+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]; 
相关问题