<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 14.0.0 -",
    "tvOS: 17.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVCaptureDevice/setFocusModeLocked(lensPosition:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVCaptureDevice(im)setFocusModeLockedWithLensPosition:completionHandler:"
  },
  "title" : "setFocusModeLocked(lensPosition:completionHandler:)"
}
-->

# setFocusModeLocked(lensPosition:completionHandler:)

Locks the lens position at the specified value, and sets the focus mode to a locked state.

```
func setFocusModeLocked(lensPosition: Float, completionHandler handler: (@Sendable (CMTime) -> Void)? = nil)
```

## Parameters

`lensPosition`

The lens position. Pass a value of [`currentLensPosition`](/documentation/AVFoundation/AVCaptureDevice/currentLensPosition) to leave the current lens position unchanged.

`handler`

A callback the system invokes when the adjustment to the lens position is complete and the [`focusMode`](/documentation/AVFoundation/AVCaptureDevice/focusMode-swift.property) set to a locked state. If you call this method multiple times, the system calls the completion handlers in FIFO order.

    The system passes a time value that matches that of the first buffer to which its applied all settings. It synchronizes the timestamp to the device clock, and you must convert the timestamp to the [`synchronizationClock`](/documentation/AVFoundation/AVCaptureSession/synchronizationClock)     prior to comparison with the timestamps of buffers delivered through an [`AVCaptureVideoDataOutput`](/documentation/AVFoundation/AVCaptureVideoDataOutput)    .

    You can pass     `nil`     for this parameter if you don’t require this information.

## Discussion

Calling this method is the only way to set the value of the [`lensPosition`](/documentation/AVFoundation/AVCaptureDevice/lensPosition) property. This method throws an exception if you set the value to an unsupported level.

Before changing the value the lens position, you must call [`lockForConfiguration()`](/documentation/AVFoundation/AVCaptureDevice/lockForConfiguration()) to acquire exclusive access to the device’s configuration properties. Otherwise, setting the value of this property raises an exception. When you finish configuring the device, call [`unlockForConfiguration()`](/documentation/AVFoundation/AVCaptureDevice/unlockForConfiguration()) to release the lock and allow other devices to configure the settings.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)