自定义相机视图无法在iOS 8 / Xcode 6上运行

所以当我在我的手机和Xcode 5.1上安装iOS 7时,我已经将此代码用于我的另一个应用程序上拍摄自定义相机视图的照片,现在在iOS 8和Xcode 6上,相机正常工作,但我看不到直播在我的leftVertical UIView中的相机视图。 这是我的代码,非常感谢任何帮助谢谢!

#import  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]; 

尝试这个…

在-viewWillAppear中:在主线程上启动相机捕获,就像这样..

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