Skip to main content

Auto Selfie

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​

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​

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​

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.