如何从photolibrary中获取所选图像的名称

时间:2013-08-07 05:59:31

标签: xcode uiimagepickercontroller filenames

在我的应用程序中,我必须使用来自photolibrary的照片,我可以从库中获取照片,并且可以在我的应用程序中使用它,但我无法获得所选图像的名称

我正在使用这个

 //accessing photo library like this
-(IBAction)btnAttachFileClicked:(id)sender
{
if([UIImagePickerController isSourceTypeAvailable:
    UIImagePickerControllerSourceTypePhotoLibrary])
{
    UIImagePickerController *picker= [[UIImagePickerController alloc]init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;


 [self presentModalViewController:picker animated:YES];

        [picker release];


    }
}


//to get name of the selected image i'm using this

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
{


    NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];

    __block NSString *fileName = nil;

    ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease];
    [library assetForURL:assetURL resultBlock:^(ALAsset *asset)  {
        fileName = [asset.defaultRepresentation filename];
    } failureBlock:nil];



}

但是我从这段代码在模拟器上测试时无法获取图像名称,我导入了AssetsLibrary框架,有什么修改可以帮助我

我将assetUrl称为“assets-library://asset/asset.PNG?id = 8542B1A1-7EAD-4CCB-A85B-8450826B49FA& ext = PNG”

0 个答案:

没有答案