title: Include UIImagePickerController in a view
body: <p>I need to make a view that works like pages<a href="https://i.stack.imgur.com/uMG2V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uMG2V.png" alt="works like pages"></a>, with a popup in which I can choose to pick a photo from my library or create a new one.</p>
  
  <p>Currently, I have a ViewController, present as Popover. In the ViewController, I inserted a ContainerView and I declared that its class is UIImageViewController. This is showing me the photo library but I don't find how to pick anything in : <a href="https://i.stack.imgur.com/1wMF9.png" rel="nofollow noreferrer">My ViewController presented as Popover</a>.</p>
  
  <p>When I choose a photo, nothing's happening. I've tried to put some functions</p>
  
  <pre><code> (func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!)) 
  </code></pre>
  
  <p>in my ViewController but it does not work. I've read that UIImagePickerController does not support subclassing, so how Pages do this stuff ?</p>
  
  <p>Here is my ViewController code :</p>
  
  <pre><code>import UIKit
  
  class MenuAddResources: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
  
      var newMedia: Bool?
      let imagePicker = UIImagePickerController()
  
      @IBAction func takePhoto(sender: AnyObject) {
              if(UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){
              //load the camera interface
              let picker : UIImagePickerController = UIImagePickerController()
              picker.sourceType = UIImagePickerControllerSourceType.Camera
              picker.delegate = self
              picker.allowsEditing = false
              self.presentViewController(picker, animated: true, completion: nil)
              self.newMedia = true
          }
          else{
              //no camera available
              let alert = UIAlertController(title: NSLocalizedString("ERROR", comment: ""), message: NSLocalizedString("NO_CAMERA", comment: ""), preferredStyle: .Alert)
              alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .Default, handler: {(alertAction)in
              alert.dismissViewControllerAnimated(true, completion: nil)
          }))
              self.presentViewController(alert, animated: true, completion: nil)
          }
      }
      override func viewDidLoad() {
          super.viewDidLoad()
  
      }
  
      func image(image: UIImage, didFinishSavingWithError error: NSErrorPointer, contextInfo:UnsafePointer&lt;Void&gt;) {
          if error != nil {
              let alert = UIAlertController(title: NSLocalizedString("ERROR", comment: ""), message: NSLocalizedString("IMAGE_SAVE_FAILED", comment: ""), preferredStyle: UIAlertControllerStyle.Alert)
  
              let cancelAction = UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .Cancel, handler: nil)
  
              alert.addAction(cancelAction)
              self.presentViewController(alert, animated: true, completion: nil)
          }
      }
  
      func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!){
          self.dismissViewControllerAnimated(true, completion: { () -&gt; Void in
          })
  
          // Let's store the image
          let now:Int = Int(NSDate().timeIntervalSince1970)
          let imageData = UIImageJPEGRepresentation(image, 85)
          //imageData?.writeToFile(documentsDirectory + "/\(now).jpg", atomically: true)
          print(imageData)
  
          /* will do stuff with the image */
      }
  
      func imagePickerControllerDidCancel(picker: UIImagePickerController) {
          self.dismissViewControllerAnimated(true, completion: nil)
      }
  
  }
  </code></pre>