How to add an image from gallery and camera in IOS Objective C

Adding images from cell phones is a very important task in Mobile Application development. Social media, Bussiness applications, Real estate applications, Lifestyle applications, E-commerce applications. We would require getting images from users where we are using “UIImagePickerControllerDelegate” Delegates. UIImagePickerControllerDelegate has a set of functions by using this delegate objects are able to interact with image picker interface. It inherits from NSObjectProtocol.

How to add an image from gallery and camera in IOS Objective C


For getting additional information about the picked object it may be image or video, UIImagePickerControllerDelegate has provided some predefined keys for a delegate object to know what exactly returned. Like ImagePickerControllerMediaType to specify that type of media returned from delegate object. ImagePickerControllerOriginalImage specifies that uncropped and original image. ImagePickerControllerImageUrl represent path/URL of returned image. ImagePickerControllerMediaMetaData returns information regarding to newly captured image.

ImagePickerControllerEditedImage specifies that the image is edited by user or not. ImagePickerControllerEditedImage presenting selected or captured image. Follow the below steps to pick an image from the gallery or capture it from the camera.  

1) Create a new project imagePickerDemo.  

2) Add  NSPhotoLibraryUsageDescription into info.plist  

3) Create a button and add action to it.

4) Add imageView in ViewController and Add outlet of it.


5) Add UIImagePickerControllerDelegate. Create one variable for UIImagePickerController.And image for storing image temporary purpose

code:

6) Add UIActionSheet when user clicking button action method.

code:

7)Add UIActionSheet method clickedButtonAtIndex
Code:

8) Add imagepickerDelegate for didFinishPickingMediaWithInfo    

Code:

Now see the Output Thank you. Please comment and share the article if you find something useful. Happy Coding.  

4 thoughts on “How to add an image from gallery and camera in IOS Objective C”

Leave a Comment