Geo
Geo

Reputation: 61

AVCapturePhotoSettings error in ios 10?

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.

Upvotes: 1

Views: 2880

Answers (2)

dengApro
dengApro

Reputation: 4008

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

Upvotes: 0

Klevison
Klevison

Reputation: 3484

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

Upvotes: 1

Related Questions