I am using the UIImagePickerController in two cases
- to select an existing image in the Photo Library
- to take a new picture
In the first case, when I choose an image form the library, I can easily get the URL in the delegate method:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Get the URL
NSURL *url = [info valueForKey:UIImagePickerControllerReferenceURL];
...
}
But when I take a new picture, the image is not yet in the photo library and has no URL yet. So, I first need to add the image in the Library. But then, how to get the URL of the new asset?
Here is my code to add the image in the Photo Library
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Get the image
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Add the image in the library
[[PHPhotoLibrary sharedPhotoLibrary]
performChanges:^
{
// Request creating an asset from the image.
PHAssetChangeRequest *createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
// Get the URL of the new asset here ?
...
}
completionHandler:^(BOOL success, NSError *error)
{
if (!success) { ...; return; }
// Get the URL of the new asset here ?
...
}
];
}