Skip to main content

Document Capture

You can use this module, if you want to uplaod files such as certificate of residence or utility bills to our system. This module is generally used for address verification, as the user should upload the files.

This module also contains a crop functionality when the customer takes a photo of a document, they'll be requested to crop image they took. Because of this function, we don't actually need a confirmation screen for every page of the document.

You can access the module from the base Amani class.

let amaniDocumentCapture = Amani.sharedInstance.document()

Setting the type

By simply calling the setType function, you can set the what type of the document the user is uploading.

note

This type is supplied by Amani to it's customers. The type below is an example.

amaniDocumentCapture.setType(type: "XXX_XX_0")
caution

If you skip this step, you will see an exception message.

Capturing documents with camera

You can start the capture process as shown in the code example.

The stepId parameter is the document page count for n-1 page. For example, if you're going to capture a 2 page document, you must set this parameter to 1.

self.documentCaptureView = try amaniDocumentCapture.start(stepId: 1) {[weak self] (previewImage) in
// previewImage is the lastly taken picture.

DispatchQueue.main.async {
self?.documentCaptureView?.removeFromSuperview()
}

} catch {
print("Unexpected error: \(error)")
}

guard let documentCaptureView = self.documentCaptureView else {return}
DispatchQueue.main.async {
self.view.addSubview(documentCaptureView)
}

Uploading the captured files

You can simply, call the upload function of this module.

amaniDocumentCapture.upload(location: nil) {(status, error) in
// status is the boolean variable if the upload successful
// if status is false, error won't be nil.
}

Uploading the documents as files

If want to upload an another type of file instead of images, such as PDF files, you simply pass an array of FileWithType struct.

FileWithType object has two values that you should provide.

  • data: The actual file Data
  • dataType: MIME type of the file.

For ease of use we've included acceptedFileTypes enum you can use the .rawValue to use it with this object.

You can also use strings for the MIME types

  • image/jpeg for jpg, jpeg, jpe
  • image/png for png
  • image/bmp for bitmap
  • image/webp for webp
  • application/pdf for pdf
  let files: [FileWithType] = [FileWithType(data: fileData, dataType: acceptedFileTypes.jpg.rawValue)]

After setting up your files array, you can pass it to the upload function. As the other modules of this SDK suggests, you can actually pass a location variable to also upload the customers location to our system. If you pass nil adding the location will be skipped.

amaniDocumentCapture.upload(location: nil, files: files) {(status, error) in
// status is the boolean variable if the upload successful
// if status is false, error won't be nil.
}