iOS 7.1 imagePicker CameraFlashMode not indicating Flash state

前端 未结 4 2047
隐瞒了意图╮
隐瞒了意图╮ 2021-02-19 20:36

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

switch ([self.imagePi         


        
4条回答
  •  时光取名叫无心
    2021-02-19 21:17

    Try to use AVCaptureDevice:

        Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice");
    
        if (captureDeviceClass != nil) {
            AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    
            [device lockForConfiguration:nil];
    
            if ([device hasTorch]) {
              if (device.torchMode ==  AVCaptureTorchModeAuto) {
                NSLog(@"Auto");
              }
              if (device.torchMode ==  AVCaptureTorchModeOn) {
                NSLog(@"On");
              }
              if (device.torchMode ==  AVCaptureTorchModeOff) {
                NSLog(@"Of");
              }
            }
    
            if ([device hasFlash]) {
              if (device.flashMode ==  AVCaptureFlashModeAuto) {
                NSLog(@"Auto");
              }
              if (device.flashMode ==  AVCaptureFlashModeOn) {
                NSLog(@"On");
              }
              if (device.flashMode ==  AVCaptureFlashModeOff) {
                NSLog(@"Of");
              }
            }
            [device unlockForConfiguration];
        }
    

提交回复
热议问题