设置相机闪光灯在 iOS 10 时不工作

Setting camera flash not working in iOS 10

无法为 iOS 版本 10 及更高版本正确设置相机闪光灯(这在 iOS 9 中工作正常)。它始终默认为 UIImagePickerControllerCameraFlashModeAuto。

这是我的代码:

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];

所以我想我必须等待 UIImagePickerController 被渲染并再次设置相机闪光灯。

所以我更新了

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

[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];
    }
}];

希望这对您有所帮助。