在应用程序使用iOS9图片模式时拍摄照片时出现iOS NSInternalInconsistencyException

在应用程序使用iOS9图片模式时拍摄照片时出现iOS NSInternalInconsistencyException,第1张

概述我在尝试拍摄照片时遇到了崩溃(前置摄像头),只有在用户使用图片模式拍摄单独的应用视频时才会失败.如果用户没有图片中的视频,一切正常.崩溃发生在这一行: [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef image 我在尝试拍摄照片时遇到了崩溃(前置摄像头),只有在用户使用图片模式拍摄单独的应用视频时才会失败.如果用户没有图片中的视频,一切正常.崩溃发生在这一行:

[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所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1073994.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存