How to get UIImagePicker selected image name?

大城市里の小女人 提交于 2019-11-30 16:04:53

With the help of ALAsset you can able to achieve this.

Step 1: Get the Asset for the selected Image from the UIImagePicker

Step 2: Get the ALAssetRepresentation for that Asset.

Step 3: ALAssetRepresentation class has a property called fileName

- (NSString *)filename

Returns a string representing the filename of the representation on disk.

This Sample Code will Helps you...

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

    NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
    {
        ALAssetRepresentation *representation = [myasset defaultRepresentation];
        NSString *fileName = [representation filename];
        NSLog(@"fileName : %@",fileName);
    };

    ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
    [assetslibrary assetForURL:imageURL 
                   resultBlock:resultblock
                  failureBlock:nil];

}

NOTE: It works only in iOS 5 and later.

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