UIImagePickerController provides an almost out of the box solution to allow the user to select an image from their device or take a picture with the camera and then present that image. By conforming to the UIImagePickerControllerDelegate, you can create logic that specifies in your app how to present the image and what to do with it (using didFinishPickingMediaWithInfo) and also what to do if the user declines to select an image or take a picture (using imagePickerControllerDidCancel).
Generic usage of UIImagePickerController
Step 1: Create the controller, set the delegate, and conform to the protocol
note: We actually will not implement anything defined in UINavigationControllerDelegate, but UIImagePickerController inherits from UINavigationController and changes the behavior of UINavigationController. Therefore, we still need to say our view controller conforms to UINavigationControllerDelegate.
Step 2: Whenever you need to show UIImagePickerController:
Step 3: Implement the delegate methods:
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0