An example of getting a photo without using UIImagePickerController:
#import <AVFoundation/AVFoundation.h> @interface TestViewController () @property (nonatomic, strong) AVCaptureSession *session; @property (nonatomic, strong) AVCaptureStillImageOutput *stillImageOutput; @property (weak, nonatomic) IBOutlet UIImageView *tmpImageView; @end @implementation TestViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self p_configureSecretCamera]; } #pragma mark - Class API - (void)takePhoto { [self p_takeSecretPhoto]; } #pragma mark - Private Methods - (void)p_configureSecretCamera { self.session = [[AVCaptureSession alloc] init]; [self.session setSessionPreset:AVCaptureSessionPresetPhoto]; AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; NSError *error; AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&error]; if ([self.session canAddInput:deviceInput]) { [self.session addInput:deviceInput]; } AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session]; [previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; self.stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil]; [self.stillImageOutput setOutputSettings:outputSettings]; [self.session addOutput:_stillImageOutput]; [self.session startRunning]; } - (void)p_takeSecretPhoto { AVCaptureConnection *videoConnection = nil; for (AVCaptureConnection *connection in self.stillImageOutput.connections) { for (AVCaptureInputPort * port in [connection inputPorts]) { if ([[port mediaType] isEqual:AVMediaTypeVideo]) { videoConnection = connection; break; } } if (videoConnection) { break; } } [self.stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { if (imageDataSampleBuffer != NULL) { NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; UIImage *image = [UIImage imageWithData:imageData]; self.tmpImageView.image = image; // !!!: // TODO: // 1. убрать звук затвора камеры при фотографировании // 2. настроить выбор камеры (фронт/бэк) // 3. отключить вспышку } }]; }
For a completely "secret" photo, you also need to remove the sound of the "camera shutter": https://stackoverflow.com/a/23758876 and turn off the flash