Taking and sharing photos is an important feature of many apps. Using the UIImagePickerViewController is a simple and easy way of enabling your user to either take a new photo or get an existing one from the user’s photo library.
Tutorial:
First of all, we want to start a new single application template project. We want to set up our main view controller, with the main image view, camera and library button.
Then we want to add an important string to our info.plist. We need to add an NSCameraUsageDescription so that we can access the devices’ camera. This is a small sentence that describes to the user why your app requires access to the camera. My sentence is only an example, you can replace it with any description you’d like.
Then we have to implement the code within our UIViewController to handle the button presses, present the UIImagePickerViewController and then handle the UIImagePickerViewControllerDelegate.
https://gist.github.com/rtking1993/a402e3b4e217a34bc44003f55f7c3f97
Here is the full source code for the project:
https://github.com/rtking1993/UIImagePickerViewController
Leave a Reply