Skip to main content

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.

Signature flow

  • G1, G2: set AmaniDelegate with setDelegate(delegate:), then start the session with initAmani(...) (optional SSL pinning before it).
  • G3: setViewArea(viewArea:), setOnConfirmPressedCallback, and your buttons: Confirm calls confirm(), Clear calls clear().
  • G4: start(stepId:); add the returned view (nil means: check onError); 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 (call start() 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 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 Signature module from the sharedInstance property as shown below.

caution

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

let amaniSignature = Amani.sharedInstance.signature()

Preparetion for starting the signature module​

↑ Flow step G3

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​

↑ Flow step G4

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​

↑ Flow step G5

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
}
}
note

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