大佬教程收集整理的这篇文章主要介绍了在应用程序使用iOS9图片模式时拍摄照片时出现iOS NSInternalInconsistencyException,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer,NSError *error) {
有错误
*** TerminaTing app due to uncaught exception 'NSInternalInconsistencyException',reason: '*** -[AVCaptureStillImageOutput captureStillImageAsynchronouslyFromConnection:completionHandler:] - inconsistent state.'
我尝试检查手机是否在使用图片模式时无法拍摄照片,但默认的iOS相机应用程序可以拍摄照片(尽管它可能使用不同的拍照方法). stillImageOutput和videoConnection似乎设置得很好,并不是零.
以下是导致此崩溃的代码,以防它有所帮助.
avCaptureSession = [[AVCaptureSession alloc] init]; AVCaptureDevice* cameraDevice = [GS60_FriendFeed_ScreenshotSelfie_Preview_View frontFacingCameraIfAvailable]; avCaptureSession.sessionPreset = avCaptureSessionPresetString; NSError *error = nil; AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:cameraDevice error:&error]; if (!input) { NSLog(@"ERROR: trying to open camera: %@",error); } [avCaptureSession addInput:input]; AVCaptureStillImageOutput* stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; NSDictionary *outputSetTings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG,AVVideoCodecKey,nil]; [stillImageOutput setOutputSetTings:outputSetTings]; [avCaptureSession addOutput:stillImageOutput]; [avCaptureSession startRunning];
然后
AVCaptureConnection* videoConnection = nil; AVCaptureStillImageOutput* stillImageOutput = [[avCaptureSession outputs] objectATindex:0]; for (AVCaptureConnection* connection in stillImageOutput.connections) { for (AVCaptureInputPort *port in [connection inputPorts]) { if ([[port mediaType] isEqual:AVMediaTypeVideo] ) { videoConnection = connection; break; } } if (videoConnection) { break; } } UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; AVCaptureVideoOrientation avcaptureOrientation = AVCaptureVideoOrientationPorTrait; if(orientation == UIInterfaceOrientationUnkNown) { avcaptureOrientation = AVCaptureVideoOrientationPorTrait; } else if(orientation == UIInterfaceOrientationPorTrait) { avcaptureOrientation = AVCaptureVideoOrientationPorTrait; } else if(orientation == UIInterfaceOrientationPorTraitUpsideDown) { avcaptureOrientation = AVCaptureVideoOrientationPorTraitUpsideDown; } else if(orientation == UIInterfaceOrientationLandscapeLeft) { avcaptureOrientation = AVCaptureVideoOrientationLandscapeLeft; } else if(orientation == UIInterfaceOrientationLandscapeRight) { avcaptureOrientation = AVCaptureVideoOrientationLandscapeRight; } [videoConnection setVideoOrientation:avcaptureOrientation]; //this line flips the image so it uses exactly what the preview shows [videoConnection setVideoMirrored:YES]; [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer,NSError *error) { ...
我希望能够拍摄照片,但是如果图片中的图片是开放的那样是不可能的,那么知道如何检测到我们将无法拍摄它仍然会有所帮助.
谢谢你的帮助.
if (!videoConnection || !videoConnection.enabled || !videoConnection.activE) { // Raise error here / warn user... return; } UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; AVCaptureVideoOrientation avcaptureOrientation = AVCaptureVideoOrientationPorTrait;
以上是大佬教程为你收集整理的在应用程序使用iOS9图片模式时拍摄照片时出现iOS NSInternalInconsistencyException全部内容,希望文章能够帮你解决在应用程序使用iOS9图片模式时拍摄照片时出现iOS NSInternalInconsistencyException所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。