UIImagePickerControllerDelegate Protocol Reference

Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 2.0 and later.
Declared in
UIImagePickerController.h
Related sample code

Overview

The UIImagePickerControllerDelegate protocol defines methods that your delegate object must implement to interact with the image picker interface. The methods of this protocol notify your delegate when the user either picks an image or movie, or cancels the picker operation.

The delegate methods are responsible for dismissing the picker when the operation completes. To dismiss the picker, call the dismissModalViewControllerAnimated: method of the parent controller responsible for displaying the UIImagePickerController object.

To save a still image to the user’s Camera Roll album, call the UIImageWriteToSavedPhotosAlbum function from within the body of the imagePickerController:didFinishPickingMediaWithInfo: method. To save a movie to the user’s Camera Roll album, instead call the UISaveVideoAtPathToSavedPhotosAlbum function. These functions, described in UIKit Function Reference, save the image or movie only; they do not save metadata.

Starting in iOS 4.0, you can save still-image metadata, along with a still image, to the Camera Roll. To do this, use the writeImageToSavedPhotosAlbum:metadata:completionBlock: method of the Assets Library framework. See the description for the UIImagePickerControllerMediaMetadata key.

Tasks

Closing the Picker

Instance Methods

imagePickerController:didFinishPickingMediaWithInfo:

Tells the delegate that the user picked a still image or movie.

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

The controller object managing the image picker interface.

info

A dictionary containing the original image and the edited image, if an image was picked; or a filesystem URL for the movie, if a movie was picked. The dictionary also contains any relevant editing information. The keys for this dictionary are listed in “Editing Information Keys.”

Discussion

Your delegate object’s implementation of this method should pass the specified media on to any custom code that needs it, and should then dismiss the picker view.

When editing is enabled, the image picker view presents the user with a preview of the currently selected image or movie along with controls for modifying it. (This behavior is managed by the picker view prior to calling this method.) If the user modifies the image or movie, the editing information is available in the info parameter. The original image is also returned in the info parameter.

If you set the image picker’s showsCameraControls property to NO and provide your own custom controls, you can take multiple pictures before dismissing the image picker interface. However, if you set that property to YES, your delegate must dismiss the image picker interface after the user takes one picture or cancels the operation.

Implementation of this method is optional, but expected.

Availability
  • Available in iOS 3.0 and later.
Declared In
UIImagePickerController.h

imagePickerControllerDidCancel:

Tells the delegate that the user cancelled the pick operation.

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
Parameters
picker

The controller object managing the image picker interface.

Discussion

Your delegate’s implementation of this method should dismiss the picker view by calling the dismissModalViewControllerAnimated: method of the parent view controller.

Implementation of this method is optional, but expected.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIImagePickerController.h

Constants

Editing Information Keys

Keys for the editing information dictionary passed to the delegate.

NSString *const UIImagePickerControllerMediaType;
NSString *const UIImagePickerControllerOriginalImage;
NSString *const UIImagePickerControllerEditedImage;
NSString *const UIImagePickerControllerCropRect;
NSString *const UIImagePickerControllerMediaURL;
NSString *const UIImagePickerControllerReferenceURL;
NSString *const UIImagePickerControllerMediaMetadata;
Constants
UIImagePickerControllerMediaType

Specifies the media type selected by the user.

The value for this key is an NSString object containing a type code such as kUTTypeImage or kUTTypeMovie.

Available in iOS 3.0 and later.

Declared in UIImagePickerController.h.

UIImagePickerControllerOriginalImage

Specifies the original, uncropped image selected by the user.

The value for this key is a UIImage object.

Available in iOS 2.0 and later.

Declared in UIImagePickerController.h.

UIImagePickerControllerEditedImage

Specifies an image edited by the user.

The value for this key is a UIImage object.

Available in iOS 3.0 and later.

Declared in UIImagePickerController.h.

UIImagePickerControllerCropRect

Specifies the cropping rectangle that was applied to the original image.

The value for this key is an NSValue object containing a CGRect opaque type.

Available in iOS 2.0 and later.

Declared in UIImagePickerController.h.

UIImagePickerControllerMediaURL

Specifies the filesystem URL for the movie.

The value for this key is an NSURL object.

Available in iOS 3.0 and later.

Declared in UIImagePickerController.h.

UIImagePickerControllerReferenceURL

The Assets Library URL for the original version of the picked item.

After the user edits a picked item—such as by cropping an image or trimming a movie—the URL continues to point to the original version of the picked item.

The value for this key is an NSURL object.

Available in iOS 4.1 and later.

Declared in UIImagePickerController.h.

UIImagePickerControllerMediaMetadata

Metadata for a newly-captured photograph.

This key is valid only when using an image picker whose source type is set to UIImagePickerControllerSourceTypeCamera, and applies only to still images.

The value for this key is an NSDictionary object that contains the metadata of the photo that was just captured. To store the metadata along with the image in the Camera Roll, use the writeImageToSavedPhotosAlbum:metadata:completionBlock: method of the Assets Library framework.

Available in iOS 4.1 and later.

Declared in UIImagePickerController.h.