AVCapturePhotoSettings error in ios 10?

2.8k views Asked by At

My application have use camera then compress image JPEG, with ios version < 10 , I have use AVCaptureStillImageOutput but ios version >= 10 I use AVCapturePhotoOutput error.I have setting code:`

self.photoOutput = [[AVCapturePhotoOutput alloc] init];
        AVCapturePhotoSettings *photoSettings =
            [AVCapturePhotoSettings photoSettingsWithFormat:@{AVVideoCodecKey : AVVideoCodecJPEG}];

    [self.photoOutput capturePhotoWithSettings:photoSettings delegate:self];
    [self.session addOutput:self.photoOutput];`

I have problems when run app, app crash with error:

[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] No active and enabled video connection

Does anybody know how to use this? Thanks.

2

There are 2 answers

0
dengApro On

The sequence to make the connection is important.

self.photoOutput = [[AVCapturePhotoOutput alloc] init];
AVCapturePhotoSettings *photoSettings = [AVCapturePhotoSettings photoSettingsWithFormat:@{AVVideoCodecKey : AVVideoCodecJPEG}];
if ([self.session canAddOutput: self.photoOutput ]){
     [self.session addOutput: self.photoOutput]
}
[self.photoOutput capturePhotoWithSettings:photoSettings delegate:self];
0
Klevison On

You need to call [self.session addOutput:]; before [self.photoOutput capturePhotoWithSettings:delegate:];

Try:

self.photoOutput = [[AVCapturePhotoOutput alloc] init];
        AVCapturePhotoSettings *photoSettings =
            [AVCapturePhotoSettings photoSettingsWithFormat:@{AVVideoCodecKey : AVVideoCodecJPEG}];
[self.photoOutput capturePhotoWithSettings:photoSettings delegate:self];
[self.session addOutput:self.photoOutput];