问题
Does anyone know how to get the selected image name (the one from photo gallery) after presenting an UIImagePickerController?
回答1:
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.
来源:https://stackoverflow.com/questions/11471254/how-to-get-uiimagepicker-selected-image-name