Committed by
GitHub
Merge pull request #500 from jorgenpt/tweak-ios-camera-focus
feat(iOS): Tweak iOS camera focus settings
Showing
2 changed files
with
17 additions
and
5 deletions
| 1 | +## NEXT | ||
| 2 | + | ||
| 3 | +Improvements: | ||
| 4 | +* [iOS] No longer automatically focus on faces | ||
| 5 | + | ||
| 1 | ## 3.0.0 | 6 | ## 3.0.0 |
| 2 | This big release contains all improvements from the beta releases. | 7 | This big release contains all improvements from the beta releases. |
| 3 | In addition to that, this release contains: | 8 | In addition to that, this release contains: |
| @@ -124,12 +124,8 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -124,12 +124,8 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 124 | // Open the camera device | 124 | // Open the camera device |
| 125 | if #available(iOS 13.0, *) { | 125 | if #available(iOS 13.0, *) { |
| 126 | device = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInTripleCamera, .builtInDualWideCamera, .builtInDualCamera, .builtInWideAngleCamera], mediaType: .video, position: cameraPosition).devices.first | 126 | device = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInTripleCamera, .builtInDualWideCamera, .builtInDualCamera, .builtInWideAngleCamera], mediaType: .video, position: cameraPosition).devices.first |
| 127 | - } else if #available(iOS 10.2, *) { | ||
| 128 | - device = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInDualCamera, .builtInWideAngleCamera], mediaType: .video, position: cameraPosition).devices.first | ||
| 129 | - } else if #available(iOS 10.0, *) { | ||
| 130 | - device = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: .video, position: cameraPosition).devices.first | ||
| 131 | } else { | 127 | } else { |
| 132 | - device = AVCaptureDevice.devices(for: .video).filter({$0.position == cameraPosition}).first | 128 | + device = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInDualCamera, .builtInWideAngleCamera], mediaType: .video, position: cameraPosition).devices.first |
| 133 | } | 129 | } |
| 134 | 130 | ||
| 135 | if (device == nil) { | 131 | if (device == nil) { |
| @@ -137,6 +133,17 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -137,6 +133,17 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 137 | } | 133 | } |
| 138 | 134 | ||
| 139 | device.addObserver(self, forKeyPath: #keyPath(AVCaptureDevice.torchMode), options: .new, context: nil) | 135 | device.addObserver(self, forKeyPath: #keyPath(AVCaptureDevice.torchMode), options: .new, context: nil) |
| 136 | + do { | ||
| 137 | + try device.lockForConfiguration() | ||
| 138 | + if device.isFocusModeSupported(focusMode: .continuousAutoFocus) { | ||
| 139 | + device.focusMode = .continuousAutoFocus | ||
| 140 | + } | ||
| 141 | + if #available(iOS 15.4, *) { | ||
| 142 | + device.automaticallyAdjustsFaceDrivenAutoFocusEnabled = false | ||
| 143 | + } | ||
| 144 | + device.unlockForConfiguration() | ||
| 145 | + } catch {} | ||
| 146 | + | ||
| 140 | captureSession.beginConfiguration() | 147 | captureSession.beginConfiguration() |
| 141 | 148 | ||
| 142 | // Add device input | 149 | // Add device input |
-
Please register or login to post a comment