Hello, I am creating a simple camere app where I want to turn OFF the autofocus (and set the focus within the app) then take a picture with the flash. The only problem is as soon as i set the flash and take a photo, it auto focuses even though i have set the focus mode locked and lens position? Is this even possible?
My av capture output settings:
photoOutput.isHighResolutionCaptureEnabled = true
photoOutput.isLivePhotoCaptureEnabled = false;
photoOutput.isDepthDataDeliveryEnabled = false;
photoOutput.isPortraitEffectsMatteDeliveryEnabled = false
photoOutput.isAppleProRAWEnabled = false;
photoOutput.setPreparedPhotoSettingsArray([buildPhotoSettings(flash: flash)]);
my AVCapturePhoto Settings
let photoSettings = AVCapturePhotoSettings(rawPixelFormatType: availbleRaw[0]);
photoSettings.isAutoStillImageStabilizationEnabled = false;
photoSettings.flashMode = flash ?.on :.off;
photoSettings.isHighResolutionPhotoEnabled = true;
photoSettings.isAutoRedEyeReductionEnabled = false;
my device input settings
//--white balance
let whiteBalanceValues = AVCaptureDevice.WhiteBalanceTemperatureAndTintValues(temperature: settings.whiteBalanceTemp, tint: settings.whiteBalanceTint);
let newWhiteBalance = videoDeviceInput.device.deviceWhiteBalanceGains(for:whiteBalanceValues);
let maxGain = videoDeviceInput.device.maxWhiteBalanceGain
if(newWhiteBalance.redGain > maxGain || newWhiteBalance.greenGain > maxGain || newWhiteBalance.blueGain > maxGain){
videoDeviceInput.device.unlockForConfiguration();
return (false, "WhiteBalance values are invalid (over maximum gain allowed)");
}
videoDeviceInput.device.setWhiteBalanceModeLocked(with: newWhiteBalance);
//--iso and exposure
let exposure = Float64(settings.exposure/1000);
let exposureTime = CMTime(seconds: exposure, preferredTimescale: 1000)
let iso = Float(settings.iso)
if(exposureTime > videoDeviceInput.device.activeFormat.maxExposureDuration || exposureTime < videoDeviceInput.device.activeFormat.minExposureDuration){
videoDeviceInput.device.unlockForConfiguration();
return (false, "Exposure out of bounds");
}
if(iso > videoDeviceInput.device.activeFormat.maxISO || iso < videoDeviceInput.device.activeFormat.minISO){
videoDeviceInput.device.unlockForConfiguration();
return (false, "ISO out of bounds");
}
videoDeviceInput.device.setExposureModeCustom(duration: exposureTime, iso: iso);
//--Lens focus
if(settings.lensPosition < 0 || settings.lensPosition>1){
videoDeviceInput.device.unlockForConfiguration();
return (false, "Lens position out of bounds");
}
if(videoDeviceInput.device.isFocusModeSupported(.locked)){
videoDeviceInput.device.focusMode = .locked;
videoDeviceInput.device.setFocusModeLocked(lensPosition: settings.lensPosition);
}
if #available(iOS 15.4, *) {
if(videoDeviceInput.device.isFaceDrivenAutoFocusEnabled){
videoDeviceInput.device.automaticallyAdjustsFaceDrivenAutoFocusEnabled = false;
}
if(videoDeviceInput.device.isFaceDrivenAutoExposureEnabled){
videoDeviceInput.device.automaticallyAdjustsFaceDrivenAutoExposureEnabled = false;
}
if(videoDeviceInput.device.isLowLightBoostSupported){
videoDeviceInput.device.automaticallyEnablesLowLightBoostWhenAvailable = false;
}
} else {
// Fallback on earlier versions
}
//--Torch ON
videoDeviceInput.device.torchMode = settings.torch ? AVCaptureDevice.TorchMode.on :AVCaptureDevice.TorchMode.off;
if(settings.torch){
if(settings.torchLevel<0 || settings.torchLevel>1){
return (false, "Flash out of bounds");
}
try? videoDeviceInput.device.setTorchModeOn(level: Float(settings.torchLevel));
}
//--Finish
videoDeviceInput.device.unlockForConfiguration();