Custom camera view does not work on iOS 8 / Xcode 6

So, I had this code working on my other application for taking photos on a custom camera view, when I had iOS 7 on my phone and Xcode 5.1, now on iOS 8 and Xcode 6 the camera works, but I can’t see. Live image of the camera in the left Vertical UIView. Here is my code, I would appreciate any help Thank you!

#import <AVFoundation/AVFoundation.h> session = [[AVCaptureSession alloc] init]; if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) [session setSessionPreset:AVCaptureSessionPreset352x288]; else [session setSessionPreset:AVCaptureSessionPreset352x288]; AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; NSError *error; AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&error]; if ([session canAddInput:deviceInput]) { [session addInput:deviceInput]; } AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; [previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; CALayer *rootLayer = [[self view] layer]; [rootLayer setMasksToBounds:YES]; CGRect frame = self.leftVertical.frame; [previewLayer setFrame:frame]; [rootLayer insertSublayer:previewLayer atIndex:0]; ////////////////////////// stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil]; [stillImageOutput setOutputSettings:outputSettings]; [session addOutput:stillImageOutput]; [session startRunning]; 
+1
source share
1 answer

try it...

In -viewWillAppear: start capturing the camera in the main thread like this.

 dispatch_async(dispatch_get_main_queue(), ^{ if (![session isRunning]) { [session startRunning]; } }); 
0
source

Source: https://habr.com/ru/post/975820/


All Articles