Skip to content

Instantly share code, notes, and snippets.

@andrebian
Created September 24, 2015 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrebian/73321f80f0e9371c8c6b to your computer and use it in GitHub Desktop.
Save andrebian/73321f80f0e9371c8c6b to your computer and use it in GitHub Desktop.
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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment