import UIKit import MobileCoreServices class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate { @IBOutlet weak var imgView: UIImageView! var newMedia: Bool? override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func takePicture(sender: AnyObject) { if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) { let picker = UIImagePickerController() picker.delegate = self picker.sourceType = UIImagePickerControllerSourceType.Camera picker.mediaTypes = [kUTTypeImage as String] picker.allowsEditing = false self.presentViewController(picker, animated: true, completion: nil) } else { NSLog("No Camera.") let alert = UIAlertController(title: "No camera", message: "Please allow this app the use of your camera in settings or buy a device that has a camera.", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default, handler: nil)) self.presentViewController(alert, animated: true, completion: nil) } } func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: NSDictionary, editingInfo: [String : AnyObject]?) { let temp: UIImage = info[UIImagePickerControllerOriginalImage] as! UIImage print("Exibindo a imagem tirada") print(temp) imgView.image = temp self.dismissViewControllerAnimated(true, completion: nil) } }