Shubhi Shubhi - 5 months ago 33
Objective-C Question

iOS 7.1 imagePicker CameraFlashMode not indicating ON/OFF state

iOS 7.1 imagePicker CameraFlashMode not indicating ON/OFF state
I have iPhone application which overlays the camera with custom view. I have a button to switch between camera flash mode, this is the code.
self.imagePickerController.cameraFlashMode always displays auto mode.

if ( self.imagePickerController.cameraFlashMode == UIImagePickerControllerCameraFlashModeOn) {
self.imagePickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;

[self.flashButton setImage:[UIImage imageNamed:@"flashoff.png"] forState:UIControlStateNormal];
self.flashButton.selected = NO;
}
else
{
self.imagePickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;

[self.flashButton setImage:[UIImage imageNamed:@"flash.png"] forState:UIControlStateNormal];

self.flashButton.selected = YES;
}
NSLog(@"cameraFlashMode: %d",self.imagePickerController.cameraFlashMode);
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInteger:self.imagePickerController.cameraFlashMode] forKey:@"cameraFlashMode"];

Answer

When you do:

self.imagePickerController = [[UIImagePickerController alloc] init];
[self.imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
[self.imagePickerController setCameraCaptureMode:UIImagePickerControllerCameraCaptureModePhoto];
//...

(in your particular case) explicitly mention:

[imagePickerController setCameraFlashMode:UIImagePickerControllerCameraFlashModeOn];

If you don't then the camera defaults to UIImagePickerControllerCameraFlashModeAuto
and since the logic you've implemented doesn't handle this case, it remains in UIImagePickerControllerCameraFlashModeAuto