> For the complete documentation index, see [llms.txt](https://legacy-docs.usesmileid.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://legacy-docs.usesmileid.com/integration-options/mobile/ios/setting-up-the-smartselfie-camera.md).

# SmartSelfie Capture

Selfies can be captured two different ways - automatically or manually. The automatic way is to let the SDK capture the selfie when a user smiles. The manual way is to add a button to the ui, and when the button is clicked, force the SDK to use the selfie from the next captured frame. The Smart Selfie capture instructions below must be followed for both. To optionally implement the manual capture, follow the Manual capture instructions.

Smart Selfie capture instructions :

In the storyboard for the ViewController class that will capture the selfie, add a VideoPreviewView. VideoPreviewView is a custom view class that is defined in the Smile Identity SDK. It will be used to capture the selfie. To add the VideoPreviewView in the storyboard do the following steps:

1. �Add a `UIView` to a `ViewController Scene`.
2. Select the UIView, and select VideoPreviewView as the Class. Set the Module

   to Smile\_Identity\_SDK, and uncheck the Inherit Module From Target, as the image below shows.
3. Add the `VideoPreview` as an outlet and name it `previewView`
4. Next, add a `UILabel`. This label will display prompts to the user, such as “Smile”. Add the UILabel as an outlet and name it `lblPrompt`.
5. Make the `ViewController` be a delegate for the capture selfie callbacks

```swift
   class MySelfieViewController: UIViewController, CaptureSelfieDelegate
```

6\. Declare a `CaptureSelfie` var at the class level

```swift
   var captureSelfie : CatureSelfie?
```

7\. To setup selfie capturing, override the viewWillAppear function and add the following lines.

```swift
   SelfieCaptureConfig.setMaxFrameTimeout( maxFrameTimeout : 200 )

   captureSelfie = CaptureSelfie()
   captureSelfie?.setup(
       captureSelfieDelegate: self,
       userTag:SmileIDSingleton.DEFAULT_USER_TAG,
       lblPrompt: lblPrompt,
       previewView: previewView,
       useFrontCamera : Bool )
```

Where `lblPrompt` and previewView are the controls that were added the the storyboard.\
userTag is the custom user tag. In this example, it is send the default user tag value that is defined in the `SmileIDSingleton`.

Setting `useFrontCamera` indicates whether the client has chosen to use the front or back camera.

Calling `SelfieCaptureConfig.setMaxFrameTimeout()` controls how many camera frames containing a detectable face should occur before the selfie capture process times out. After the timeout, the selfie capture process completes. The default value is 120 frames. The minimum value is 8.

8\. Override the `viewDidAppear` function and add the following lines.

```swift
   captureSelfie?.start( screenRect: self.view.bounds )
```

9\. Overriding the `viewWillDisappear` function and add the following lines. This will stop the camera capture.

```swift
   guard captureSelfie != nil else {
       return; }
   captureSelfie!.stop()
```

10\. Implement the CaptureSelfieDelegate callbacks


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://legacy-docs.usesmileid.com/integration-options/mobile/ios/setting-up-the-smartselfie-camera.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
