(iOS Cam App)How to set flashMode to align the flash behavior with System Apple Camera App?

46 Views Asked by At

I am developing a custom camera app on iOS 15 and have encountered difficulties when working on the flash mechanism to make it work like the native Camera app. I noticed that when I call

[_photoOutput capturePhotoWithSettings:photoSettings delegate:self];

I can have multiple photo settings, such as:

//prepared setting
_photoOutput.preparedPhotoSettingsArray[0];

//monitoring setting
_photoOutput.photoSettingsForSceneMonitoring;

//capturing setting, actually the resolved setting by checking uniqueID in - (void)captureOutput:(AVCapturePhotoOutput *)output willBeginCaptureForResolvedSettings:(AVCaptureResolvedPhotoSettings *)resolvedSettings
photoSettings;

Each photo setting has a uniqueID and flashMode property. I guess _photoOutput.isFlashScene is calculated by photoSettingsForSceneMonitoring.flashMode and isAutoStillImageStabilizationEnabled(SIS), but the SIS is marked as deprecated and replaced by photoQualityPrioritization from iOS 13.

So there are many factors to control the flash behavior. I don't have a clear idea of how to set them to align with system flash. In my situation, when using true-depth front camera, I first setup photoOutput in the camera setup session

_photoOutput = [[AVCapturePhotoOutput alloc] init];
    
_photoOutput.highResolutionCaptureEnabled = YES;
    
_photoOutput.maxPhotoQualityPrioritization = AVCapturePhotoQualityPrioritizationQuality;
    
AVCapturePhotoSettings *settingForMonitoring = [AVCapturePhotoSettings photoSettings];

settingForMonitoring.flashMode = AVCaptureFlashModeAuto;

_photoOutput.photoSettingsForSceneMonitoring = settingForMonitoring;

...other settings

When capture button is pressed, I use the following settings:

...other settings

photoSettings = [AVCapturePhotoSettings photoSettings];

photoSettings.photoQualityPrioritization = AVCapturePhotoQualityPrioritizationQuality;

photoSettings.flashMode = AVCaptureFlashModeAuto;

if (self.inputCamera.exposureTargetBias != 0) {
    photoSettings.flashMode = AVCaptureFlashModeOff;
}
...other settings

[_photoOutput capturePhotoWithSettings:photoSettings delegate:self];

These codes work great in daylight, just like Apple Camera. However, at dusk, the flash always fires, even indoors with lights on, resulting in poor photo quality (high ISO and longer exposure time). Meanwhile, the Apple Camera doesn't fire the flash and gives better image quality.

I want to suppress the flash from firing at dusk and work at night. Can anyone tell me how to set up these flash modes or any other parameters I may be missing? Thanks!

0

There are 0 best solutions below