IOS SDK Migration
Amani Core SDK Initialization
- Core SDK V2
- Core SDK V3
class AmaniInitializaion: UIViewController {
let amani = Amani.sharedInstance
override func viewDidLoad() {
super.viewDidLoad()
amani.initAmani(
server: "ServerURL",
token: "Token",
customer: CustomerRequestModel.init(idCardNumber: "55555"))
[weak self] { customerModel, error in
print("\(customerModel), \(error)")
}
}
}
NOTE
Amani Delegate is available for use starting from Amani SDK v3.0.0 and later.
In versions below v3.0.0, delegate such as status returned as a result of document upload could be listened to once by the callback in the upload method of the relevant module. Amani Delegate replaces this structure and offers the opportunity to listen to delegate coming from the web socket in more detail.
class AmaniInitializaion: UIViewController {
let amani = Amani.sharedInstance
override func viewDidLoad() {
super.viewDidLoad()
amani.setDelegate(delegate: self)
amani.initAmani(
server: "serverURL",
token: "token",
apiVersion: .v1 //You must choose compatible with your server version.
)
{ [weak self] (customerModel, error) in
print("\(customerModel), \(error)")
}
}
}
Amani Delegate
//MARK: We are setting AmaniDelegate to ViewController
//MARK: You can handle here result of AmaniSDK responses.
extension AmaniInitializaion:AmaniDelegate{
func onError(type: String, error: [AmaniSDK.AmaniError]) {
print(type)
print(error)
}
func onProfileStatus(customerId: String, profile: AmaniSDK.wsProfileStatusModel) {
print(profile)
}
func onStepModel(customerId: String, rules: [AmaniSDK.KYCRuleModel]?) {
print(rules)
}
}
ID Module
- Core SDK V2
- Core SDK V3
class IDcaptureModule: UIViewController {
let amaniIDCapture = Amani.sharedInstance.IdCapture()
var idCaptureView: UIView? = UIView()
override func viewDidLoad() {
super.viewDidLoad()
amaniIDCapture.setType(type: "XXX_ID_0")
do {
self.idCaptureView = try amaniIDCapture.start(stepId: steps.front.rawValue) { previewImage in
print(previewImage)
}
DispatchQueue.main.async {
self.view.addSubview(self.idCaptureView!)
}
DispatchQueue.main.async {
self.idCaptureView!.removeFromSuperview()
}
amaniIDCapture.upload(location: nil) { uploadSuccess, error in
print(uploadSuccess, error)
}
}catch {
print(error)
}
}
}
For upload there is result, returning the file upload.
class IDcaptureModule: UIViewController {
let amaniIDCapture = Amani.sharedInstance.IdCapture()
var idCaptureView: UIView? = UIView()
override func viewDidLoad() {
super.viewDidLoad()
do {
let idcapture = amani.IdCapture()
idcapture.setType(type: "XXX_ID_0") //Document types are not changed for server side. You can still use what you defined on your v2.
self.idCaptureView = try idcapture.start(stepId: 0, completion: { [weak self] (previewView) in
})
// This func will return to you a UIView. You can start the process using the UIView that appears.
// ID Capture upload
amani.IdCapture().upload(location: CLLocationManager().location) { result in
print("return idupload :", result)
}
}
}
}
NFC Module with IDCapture
- Core SDK V2
- Core SDK V3
class IDcaptureModule: UIViewController {
let amaniIDCapture = Amani.sharedInstance.IdCapture()
var idCaptureView: UIView? = UIView()
override func viewDidLoad() {
super.viewDidLoad()
amaniIDCapture.setType(type: "XXX_ID_0")
//You should take front and back side of ID's. Than you can set startNFC function.
do {
self.idCaptureView = try amaniIDCapture.start(stepId: steps.front.rawValue) { previewImage in
print(previewImage)
}
DispatchQueue.main.async {
self.view.addSubview(self.idCaptureView!)
}
DispatchQueue.main.async {
self.idCaptureView!.removeFromSuperview()
}
amaniIDCapture.startNFC { isMrzRead in
print(isMrzRead)
}
amaniIDCapture.upload(location: nil) { uploadSuccess, error in
print(uploadSuccess, error)
}
}catch {
print(error)
}
}
}
class IDCaptureWithNFC: UIViewController {
var nviData:NviModel? {
didSet{
Task { @MainActor in
if let nviData = nviData {
let scannfc = await amaniScanNFC.startNFC(nvi: nviData)
}
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
let amaniScanNFC = Amani.sharedInstance.scanNfc()
amaniScanNFC.setType(type: "XXX_ID_0")
let nviData = NviModel(documentNo: "DOCUMENT NO IN ALL CAPS", dateOfBirth: "YYMMDD", dateOfExpire: "YYMMDD")
do {
let scannfc = try await amaniScanNFC.start(nvi: nviData)
} catch (let error ) {
print(error)
}
////////////////////////////////////
var stepId = steps.front.rawValue //For ID's which has MRZ Field at the front side (like passport)
let type = "XXX_ID_0"
if((type.contains("ID"))){
stepId = steps.back.rawValue ////For ID's which has MRZ Field at the back side (like ID Cards)
}
guard let idcaptureVC:UIView = try idcapture.start(stepId: stepId, completion: { [weak self] (previewImage) in
amani.IdCapture().getMrz { [weak self] mrzDocumentId in
self?.mrzDocumentId = mrzDocumentId
}
})
}
}
extension ViewController: mrzInfoDelegate {
func mrzInfo(_ mrz: AmaniSDK.MrzModel?, documentId: String?) {
guard let mrz = mrz else {return}
switch apiVersion {
case .v1:
let nviData = NviModel(mrzModel: mrz)
self.nviData = nviData
case .v2:
if documentId == mrzDocumentId {
let nviData = NviModel(mrzModel: mrz)
self.nviData = nviData
}
default:
break
}
}
}
Selfie Module
- Core SDK V2
- Core SDK V3
class SelfieModule: UIViewController {
let amaniSelfie = Amani.sharedInstance.selfie()
var selfieView: UIView? = UIView()
override func viewDidLoad() {
super.viewDidLoad()
do {
amaniSelfie.setType(type: "XXX_SE_0")
self.selfieView = try amaniSelfie.start(completion: { previewImage in
print(previewImage)
})
DispatchQueue.main.async {
self.view.addSubview(self.selfieView!)
}
DispatchQueue.main.async {
self.selfieView!.removeFromSuperview()
}
amaniSelfie.upload(location: nil) { uploadSuccess, error in
print(uploadSuccess, error)
}
}catch {
print(error)
}
}
}
class SelfieModule: UIViewController {
let amaniSelfie = Amani.sharedInstance.selfie()
var selfieView: UIView? = UIView()
override func viewDidLoad() {
super.viewDidLoad()
do {
let selfie = amani.selfie()
selfie.setType("XXX_SE_0")
// selfie.setVideoRecording(enabled: Bool) ///// If you wish you can enable video recording when user taking selfie.
self.selfieView = try selfie.start( completion: { [weak self] (previewImage) in
})
// This func will return to you a UIView. You can start the process using the UIView that appears.
//Selfie Upload
selfie.selfie().upload { isSuccess in
print("selfie upload \(isSuccess)")
}
}
}
}
Auto Selfie Module
- Core SDK V2
- Core SDK V3
class AutoSelfieModule: UIViewController {
let amaniAutoSelfie = Amani.sharedInstance.autoSelfie()
var autoSelfieView: UIView? = UIView()
override func viewDidLoad() {
super.viewDidLoad()
amaniAutoSelfie.setType(type: "XXX_SE_0")
do {
self.autoSelfieView = try amaniAutoSelfie.start { previewImage in
print(previewImage)
}
amaniAutoSelfie.upload(location: nil) { uploadSuccess, error in
print(uploadSuccess, error)
}
}catch {
print(error)
}
}
}
class AutoSelfieModule: UIViewController {
let amaniAutoSelfie = Amani.sharedInstance.autoSelfie()
var autoSelfieView: UIView? = UIView()
override func viewDidLoad() {
super.viewDidLoad()
amaniAutoSelfie.setType(type: "XXX_SE_0")
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)
}
amaniAutoSelfie.upload(location: nil) {[weak self] uploadSuccess in
if (uploadSuccess != nil) {
// uploadSuccess is a boolean variable
// TODO: handle the upload state
}
}
}catch {
print(error)
}
}