remirobert / CameraEngine

:monkey::camera: Camera engine for iOS, written in Swift, above AVFoundation. :monkey:
https://github.com/remirobert/CameraEngine
MIT License
583 stars 106 forks source link

AVCapturePhotoSettings #55

Open basuru13 opened 8 years ago

basuru13 commented 8 years ago

When taking a sequence of photos with the camera example, I get the following error:

-[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] Settings may not be re-used'

Any idea how to create a unique value for the settings?

remirobert commented 8 years ago

let me check that in detail. Thanks for reporting this issue.

natewitty commented 8 years ago

I've run into a similar problem when taking more than one photo in my app. I traced the issue back to the reuse of the self.capturePhotoSettings object that has the same uniqueId.

Here is the Apple Doc reference: https://developer.apple.com/reference/avfoundation/avcapturephotosettings

Important

It is illegal to reuse a AVCapturePhotoSettings instance for multiple captures. Calling the capturePhoto(with:delegate:) method throws an exception (invalidArgumentException) if the settings object’s uniqueID value matches that of any previously used settings object.

To reuse a specific combination of settings, use the init(from:) initializer to create a new, unique AVCapturePhotoSettings instance from an existing photo settings object.

My workaround was to modify the source code as follows.

CameraEngine.swift - line 461

public func capturePhoto(_ blockCompletion: @escaping blockCompletionCapturePhoto) {
        let uniqueSettings = AVCapturePhotoSettings.init(from: self.capturePhotoSettings)
        self.cameraOutput.capturePhoto(settings: uniqueSettings, blockCompletion)
    }

This seems to be working for me now. I hope this is helpful to you guys.