I have a preview layer that is pulling from the camera and working as it should. I would like to be able to take a picture when I press a button. I have inited the AVCaptureStil
for swift version:
@IBAction func capture(sender: AnyObject) {
var videoConnection :AVCaptureConnection?
if let videoConnection = stillImageOutput.connectionWithMediaType(AVMediaTypeVideo){
stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: { (buffer:CMSampleBuffer!, error: NSError!) -> Void in
if let exifAttachments = CMGetAttachment(buffer, kCGImagePropertyExifDictionary, nil) {
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(buffer)
self.previewImage.image = UIImage(data: imageData)
UIImageWriteToSavedPhotosAlbum(self.previewImage.image, nil, nil, nil)
}
})
}
}