Setting up the Smart Selfie Camera

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

    class MySelfieViewController: UIViewController, CaptureSelfieDelegate
  6. Declare a CaptureSelfie var at the class level

    var captureSelfie : CatureSelfie?
  7. To setup selfie capturing, override the viewWillAppear function and add the following lines.

    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.

    captureSelfie?.start( screenRect: self.view.bounds )
  9. Overriding the viewWillDisappear function and add the following lines. This will stop the camera capture.

    guard captureSelfie != nil else {
    return; }
    captureSelfie!.stop()
  10. Implement the CaptureSelfieDelegate callbacks