Is it possible to get an image from the camera of the phone (with the user's permission to use the camera) without displaying any dialogues / previews (for example, UIImagePickerController)?

those. in simple words - at a certain moment (when a button was pressed or programmatically) they turned to the camera and obtained a UIImage for further processing, while the interface did not change on the screen.

If this is possible, can you link to an example with similar / similar functionality?

  • after the user has allowed the application to use the camera, the program no longer tests the program, it can take pictures, including covertly (if the device does not have a hardware indicator of the enabled exposure mode). The question is just what to do next - send a message over the network - atomic traffic will rise, do some kind of analysis ... maybe in order to send someone 100 kilobytes once a day :) - Eugene Bartosh
  • on iphons / ipads "there is a hardware indicator for the enabled exposure mode"? or is it an abstract comment? - xhr
  • it's not there - at least on my iPad Air 2 :-) But maybe on other models, I didn’t check everything :-) Or on future models - Eugene Bartosh

1 answer 1

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