cinnamonlao
cinnamonlao

Reputation: 27

Setting camera flash not working in iOS 10

Cannot set the camera flash properly for iOS versions 10 and above (this is working correctly in iOS 9). It always defaults to UIImagePickerControllerCameraFlashModeAuto.

Here's my code:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[picker setAllowsEditing:NO];
[picker setDelegate:self];
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[picker setCameraFlashMode:UIImagePickerControllerCameraFlashModeOn];
[picker setCameraOverlayView:overlayView];
[self presentViewController:picker animated:YES completion:Nil];

Upvotes: 1

Views: 352

Answers (1)

cinnamonlao
cinnamonlao

Reputation: 27

So I guess I have to wait for the UIImagePickerController to be rendered and set the camera flash again.

So I updated

[self presentViewController:picker animated:YES completion:nil];

to

[self presentViewController:picker animated:YES completion:^{
    //For iOS 10 and higher versions so it can set the proper flashmode
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10) {
       [picker setCameraFlashMode:UIImagePickerControllerCameraFlashModeOn];
    }
}];

Hope this could help.

Upvotes: 2

Related Questions