How to do it...

To provide options for users to pick an image, perform the following steps:

  1. Create a new Xcode project with the Single View Application template and name it ImageVideoPicker.
  2. Add a button at the center of the screen to pick a photo or video. Change the title of the button to Pick photo / video.
  3. Add IBAction to the button in ViewController.swift, like this:
     @IBAction func didClickOnPickButton(_ sender:
         AnyObject) { 
         
     } 
  1. We will ask the user to choose whether to pick a photo/video from the saved photos or by capturing from camera before picking.
  2. First, let's add the code that will display an action sheet to the user to select an action from:
 @IBAction func didClickOnPickButton(_ sender: AnyObject) { let actionSheetController ...

Get iOS Programming Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.