# How to get the image picker in (swift 3) to switch back and 4th between photo gallery and camera

**URL:** <https://forums.kodeco.com/t/how-to-get-the-image-picker-in-swift-3-to-switch-back-and-4th-between-photo-gallery-and-camera/20663>\
**Category:** Swift\
**Created:** [October 3, 2016, 2:11pm UTC](https://forums.kodeco.com/t/how-to-get-the-image-picker-in-swift-3-to-switch-back-and-4th-between-photo-gallery-and-camera/20663 "2016-10-03T14:11:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zalubski](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/zalubski/32/81494_2.png) [@zalubski](https://forums.kodeco.com/u/zalubski)\
**Post date:** [October 3, 2016, 2:11pm UTC](https://forums.kodeco.com/t/how-to-get-the-image-picker-in-swift-3-to-switch-back-and-4th-between-photo-gallery-and-camera/20663/1 "2016-10-03T14:11:48Z")

</div>

This code allows access to my photo gallery on the iPhone simulator in Xcode. When I put it on my iPad I can access the camera but not the photo gallery. I would like the image view to display the camera photos if choose or load a image from the photo gallery if choose.

```
                           import UIKit

   class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

   let picker = UIImagePickerController()
 @IBOutlet weak var iv: UIImageView!

    @IBAction func cameraf(_ sender: UIBarButtonItem) {

if UIImagePickerController.isSourceTypeAvailable(.camera) {
    picker.allowsEditing = false
    picker.sourceType = UIImagePickerControllerSourceType.camera
    picker.cameraCaptureMode = .photo
    picker.modalPresentationStyle = .fullScreen
    present(picker,animated: true,completion: nil)
} else {
    noCamera()
}}

      @IBAction func photolibaryss(_ sender: UIBarButtonItem) {
picker.allowsEditing = false
picker.sourceType = .photoLibrary
picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
picker.modalPresentationStyle = .popover
present(picker, animated: true, completion: nil)
picker.popoverPresentationController?.barButtonItem = sender
         }

      func noCamera(){
let alertVC = UIAlertController(
    title: "No Camera",
    message: "Sorry, this device has no camera",
    preferredStyle: .alert)
let okAction = UIAlertAction(
    title: "OK",
    style:.default,
    handler: nil)
alertVC.addAction(okAction)
present(
    alertVC,
    animated: true,
    completion: nil)
      }
     override func viewDidLoad() {
        super.viewDidLoad()
              picker.delegate = self
              }
               func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
         {
        var chosenImage = UIImage()
        chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
           iv.contentMode = .scaleAspectFit
         iv.image = chosenImage
             dismiss(animated:true, completion: nil)
       }
        func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
               dismiss(animated: true, completion: nil)
        }
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
             // Dispose of any resources that can be recreated.
              }}

```
