Signature
This module creates a canvas, and lets the users upload their signatures.
Flow overviewFlowchart of this module's usage within the SDK flow. Expand to view it, click the chart to enlarge.
- G1, G2: set
AmaniDelegatewithsetDelegate(delegate:), then start the session withinitAmani(...)(optional SSL pinning before it). - G3:
setViewArea(viewArea:),setOnConfirmPressedCallback, and your buttons: Confirm callsconfirm(), Clear callsclear(). - G4:
start(stepId:); add the returned view (nil means: checkonError); the completion brings the last signature. - G5: upload the signatures. If the upload fails or the step is REJECTED, do not call
upload()again: the data is cleared after it. Open the canvas again (callstart()and add the new view, or show your kept view again), capture, then upload, up to your own max attempt. - G6, G7: follow the verdicts in
onStepModel/onProfileStatus, and callendSession()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 Signature module from the sharedInstance property as shown below.
Before using this module please make sure you've initialized the SDK correctly.
let amaniSignature = Amani.sharedInstance.signature()
Preparetion for starting the signature module
Before calling the start method of this module you have to create a view to be used as canvas, and create a to setup as confirm and and clear.
// setting the canvas frame
// for example purposes we used the whole frame of the view controller
// TODO: change this for a different view like a subview that needs to be drawable
amaniSignature.setViewArea(viewArea: view.bounds)
// setting the buttons
@IBAction func clearAct(_ sender: UIButton) {
amaniSignature.clear()
}
@IBAction func confirmAct(_ sender: UIButton) {
amaniSignature.confirm()
}
// setting the callbacks
amaniSignature.setOnConfirmPressedCallback {(image, currentSignatureNo) in
// TODO: do something with image
// TODO: do something with currentSignatureNo
}
Starting the module
Just call the start method, if you want to capture multiple set the stepId
to the n-1 of the acutal count you want.
self.signatureView = amaniSignature.start(stepId: 2) {(previewImage) in
// preview image is the lastly taken signature
// TODO: show a preview screen uses previewImage
// remove the view
DispatchQueue.main.async {
self.signatureView.removeFromSuperview()
}
}
// add the view
DispatchQueue.main.async {
self.view.addSubview(signatureView)
}
Upload
After completing the capture process you can call the upload as shown below.
amaniSignature.upload(location: nil) {[weak self] isSuccess in
if (isSuccess != nil) {
// isSuccess 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.
amaniSignature.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
}
}
The closure with only isSuccess still works. You don't need to change your existing integration.