Skip to main content

Auto Selfie

Auto Selfie takes the user's selfie automatically when the face is inside the area and stable.

Flow overviewFlowchart of this module's usage within the SDK flow. Expand to view it, click the chart to enlarge.

Auto Selfie flow

  • A1, A2: set AmaniDelegate with setDelegate(delegate:), then start the session with initAmani(...) (optional SSL pinning before it).
  • A3: autoSelfie(), setType(type:), the optional messages and screen config, then start(); add the returned view (nil means: check onError).
  • A4: upload the selfie. If the upload fails or the step is REJECTED, do not call upload() again: the data is cleared after it. Open the selfie again (call start() and add the new view, or show your kept view again), capture, then upload, up to your own max attempt.
  • A5, A6: follow the verdicts in onStepModel / onProfileStatus, and call endSession() at the end.
  • Other modules may come before or after it, in the order your flow needs; the chart shows it alone to keep it simple.

You can access the AutoSelfie module from the base Amani class as shown below.

caution

Before using this module please make sure you've initialized the SDK correctly.

let amaniAutoSelfie = Amani.sharedInstance.autoSelfie()

Configuration​

↑ Flow step A3

Configuring the messages​

These are the messages that you can configure. You can use this table with a dictionary in [infoMessages: String] type.

KeyTypeDescription
faceIsOkstringShows before capturing the selfie
notInAreastringShows when the user's face is not in the area
faceTooSmallstringShows when the user's face is too far
faceTooBigstringShows when the user's face is too close
completedstringShows when the process is completed
var infoMessages: [infoState: String] = [
.faceIsOk: "Please hold stable",
.notInArea: "Please align your face with the area",
.faceTooSmall:"Your face is too far",
.faceTooBig: "Your face is too close",
.completed: "All done!",
]

After creating the dictionary, you can call the setInfoMessages function with it.

amaniAutoSelfie.setInfoMessages(infoMessages: infoMessages)

Configuring the screen​

As much as you can change the info messages, you can also change the on screen and also the count timer. These are the keys that we have for configuration.

With the keys below you can create a dictionary with type of [configState: String]

KeyTypeDescription
appBackgroundColorStringHex color with no hash sign (#)
appFontColorStringHex color with no hash sign (#)
primaryButtonBackgroundColorStringHex color with no hash sign (#)
ovalBorderSuccessColorStringHex color with no hash sign (#)
ovalBorderColorStringHex color with no has sign (#)
countTimerStringNumber wrapped in a string
var screenConfig: [configState:String] = [
.appBackgroundColor: "000000",
.appFontColor: "ffffff",
.primaryButtonBackgroundColor: "ffffff",
.ovalBorderSuccessColor: "00ff00",
.ovalBorderColor: "ffffff",
.countTimer:"3"

After creating the dictionary you can call setScreenConfig with it.

amaniAutoSelfie.setScreenConfig(screenConfig: screenConfig)

Starting the Auto Selfie Capture​

↑ Flow step A3

The start method will return an instance of UIView

self.autoSelfieView = amaniAutoSelfie.start() {[weak self] previewImage in
// after the process ends you can safely remove the autoSelfieView from your view controller
DispatchQueue.main.async {
self?.autoSelfieView.removeFromSuperView()
}

// TODO: upload or show a confirm screen
}

// don't forget to add the auto selfie view to your view controller
DispatchQueue.main.async {
self.view.addSubView(self.autoSelfieView)
}

Upload​

↑ Flow step A4

After completing the capture process you can call the upload as shown below.

amaniAutoSelfie.upload(location: nil) {[weak self] uploadSuccess in
if (uploadSuccess != nil) {
// uploadSuccess is a boolean variable
// TODO: handle the upload state
}
}

Getting the documentId after the upload​

Starting with AmaniSDK 3.7.6, upload also accepts a closure with two parameters. The second parameter is the documentId of the document that the upload created.

AutoSelfie uploads through the PoseEstimation module. Because of this, call the two-parameter upload on Amani.sharedInstance.poseEstimation() after the auto selfie capture.

Amani.sharedInstance.poseEstimation().upload(location: nil) { isSuccess, documentId in
if isSuccess == true, let documentId {
// Upload succeeded, store the documentId
print("Upload completed, documentId: \(documentId)")
} else {
// Upload failed, documentId is nil
}
}
note

The closure with only isSuccess still works. You don't need to change your existing integration.