iOS Developer Library

Developer

UIKit Framework Reference UIImagePickerControllerDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIImagePickerControllerDelegate

Inherits From


Not Applicable

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later

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.

To write additional metadata when saving an image to the Camera Roll, use the PHAssetChangeRequest class from the Photos framework. See the description for the UIImagePickerControllerMediaMetadata key.

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

    Declaration

    Swift

    optional func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject])

    Objective-C

    - (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 NOfalse and provide your own custom controls, you can take multiple pictures before dismissing the image picker interface. However, if you set that property to YEStrue, 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later

  • Tells the delegate that the user picked an image.

    Deprecation Statement

    Use imagePickerController:didFinishPickingMediaWithInfo: instead.

    Declaration

    Objective-C

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo

    Parameters

    picker

    The controller object managing the image picker interface.

    image

    The image that the user picked. If user editing is enabled, this may be a cropped and adjusted version of the original image. In this case, the original image, and the editing information, are available in the editingInfo parameter.

    editingInfo

    A dictionary containing any relevant editing information. If editing is disabled, this parameter is nil. The keys for this dictionary are listed in Editing Information Keys.

    Discussion

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

    When user editing is enabled, the picker view presents the user with a preview of the currently selected image 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, the editing information is available in the editingInfo parameter. If you don’t need the editing information, simply use the image in the image parameter as is.

    Special Considerations

    This deprecated method supports picking only still pictures. The replacement method, imagePickerController:didFinishPickingMediaWithInfo:, supports picking movies as well as still pictures.

    Import Statement

    Objective-C

    @import UIKit;

    Availability

    Available in iOS 2.0 and later

    Deprecated in iOS 3.0

  • Tells the delegate that the user cancelled the pick operation.

    Declaration

    Swift

    optional func imagePickerControllerDidCancel(_ picker: UIImagePickerController)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later

  • Keys for the editing information dictionary passed to the delegate.

    Declaration

    Swift

    let UIImagePickerControllerMediaType: String let UIImagePickerControllerOriginalImage: String let UIImagePickerControllerEditedImage: String let UIImagePickerControllerCropRect: String let UIImagePickerControllerMediaURL: String let UIImagePickerControllerReferenceURL: String let UIImagePickerControllerMediaMetadata: String

    Objective-C

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

    Constants

    • UIImagePickerControllerMediaType

      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

    • UIImagePickerControllerOriginalImage

      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

    • UIImagePickerControllerEditedImage

      UIImagePickerControllerEditedImage

      Specifies an image edited by the user.

      The value for this key is a UIImage object.

      Available in iOS 3.0 and later

    • UIImagePickerControllerCropRect

      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

    • UIImagePickerControllerMediaURL

      UIImagePickerControllerMediaURL

      Specifies the filesystem URL for the movie.

      The value for this key is an NSURL object.

      Available in iOS 3.0 and later

    • UIImagePickerControllerReferenceURL

      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

    • UIImagePickerControllerMediaMetadata

      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 PHAssetChangeRequest class from the Photos framework.

      Available in iOS 4.1 and later