iOS 10相机闪光灯开/关不工作



iOS 9闪光灯开/关/自动工作正常。但是在iOS 10中flash不能工作。

    self.camObj = [[UIImagePickerController alloc] init];
    [self addCameraToTheScreen];
    NSArray *mediaTypes = [NSArray arrayWithObject:(NSString*)kUTTypeMovie];
    self.camObj.mediaTypes = mediaTypes ;
    self.camObj.modalTransitionStyle = UIModalPresentationFullScreen;
    self.camObj.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.camObj.videoMaximumDuration = 10.0f;
    self.camObj.showsCameraControls = NO;
    self.camOptionsView.frame = [UIScreen mainScreen].bounds;
    self.camObj.delegate = (id<UIImagePickerControllerDelegate,UINavigationControllerDelegate>)self;
    [self.camObj setCameraOverlayView:self.camOptionsView];

和编程改变闪光模式。

 [self.camObj setCameraFlashMode:UIImagePickerControllerCameraFlashModeOn];

iOS 10.2问题已解决。现在手动相机闪光模式处理工作正常,不需要启用和禁用showscameracontrol。

这是iOS 10的一个bug(至少从10.0.2开始)。注意,如果showsCameraControls打开,设置cameraFlashMode 工作。

这是iOS 10的一个bug,所以你需要从UIImagePickerController继承并重写camerafashmode setter:

 - (void)setCameraFlashMode:(UIImagePickerControllerCameraFlashMode)cameraFlashMode {
     if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10 && !self.showsCameraControls) {
         self.showsCameraControls = YES;
         super.cameraFlashMode = cameraFlashMode;
         self.showsCameraControls = NO;
     } else {
         super.cameraFlashMode = cameraFlashMode;
     }
 }

有报道称第三方更换部件可能会导致这些症状,特别是手机需要冷却和相机/闪光灯不工作的信息。如果检测到非苹果硬件,手机上的固件也可能会检查内置部件的真伪,这也可能导致这些问题。

对于iOS 10,尝试先渲染UIImagePickerController,然后再次设置相机闪光灯。试着

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

相关内容

  • 没有找到相关文章

最新更新