-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathIdenfyReactNative.swift
123 lines (94 loc) · 5.41 KB
/
IdenfyReactNative.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import Foundation
import iDenfySDK
import idenfyviews
@objc(IdenfyReactNative)
class IdenfyReactNative: NSObject {
@objc func start(_ config: NSDictionary,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
DispatchQueue.main.async {
self.run(withConfig: config, resolver: resolve, rejecter: reject)
}
}
@objc func startFaceReAuth(_ config: NSDictionary,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
DispatchQueue.main.async {
self.runFaceReauth(withConfig: config, resolver: resolve, rejecter: reject)
}
}
private func run(withConfig config: NSDictionary,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
do {
let authToken = GetSdkConfig.getAuthToken(config: config)
let idenfySettingsV2 = IdenfyBuilderV2()
.withAuthToken(authToken)
.build()
let idenfyColorMain = "#EA9619"
let idenfyColorButton = "#6539AC"
IdenfyCommonColors.idenfyMainColorV2 = UIColor(hexString: idenfyColorMain)
IdenfyCommonColors.idenfyMainDarkerColorV2 = UIColor(hexString: idenfyColorMain)
IdenfyCommonColors.idenfyGradientColor1V2 = UIColor(hexString: idenfyColorButton)
IdenfyCommonColors.idenfyGradientColor2V2 = UIColor(hexString: idenfyColorButton)
IdenfyToolbarUISettingsV2.idenfyDefaultToolbarBackgroundColor = UIColor(hexString: idenfyColorMain)
IdenfyToolbarUISettingsV2.idenfyDefaultToolbarBackIconTintColor = IdenfyCommonColors.idenfyBlack
IdenfyToolbarUISettingsV2.idenfyDefaultToolbarLogoIconTintColor = IdenfyCommonColors.idenfyBlack
IdenfyToolbarUISettingsV2.idenfyLanguageSelectionToolbarLanguageSelectionIconTintColor = IdenfyCommonColors.idenfyBlack
IdenfyToolbarUISettingsV2.idenfyLanguageSelectionToolbarCloseIconTintColor = IdenfyCommonColors.idenfyBlack
IdenfyCommonColors.idenfyPhotoResultDetailsCardBackgroundColorV2 = UIColor(hexString: "#FFE5BD")
IdenfyPhotoResultViewUISettingsV2.idenfyPhotoResultViewDetailsCardTitleColor = UIColor(hexString: idenfyColorButton)
let idenfyViewsV2:IdenfyViewsV2 = IdenfyViewsBuilderV2()
.withCountryCellView(CountryCell.self)
.build()
let idenfyController = IdenfyController.shared
idenfyController.initializeIdenfySDKV2WithManual(idenfySettingsV2: idenfySettingsV2, idenfyViewsV2: idenfyViewsV2)
let idenfyVC = idenfyController.instantiateNavigationController()
idenfyVC.modalPresentationStyle = .fullScreen
UIApplication.shared.windows.first?.rootViewController?.present(idenfyVC, animated: true)
handleSdkCallbacks(idenfyController: idenfyController, resolver: resolve)
} catch let error as NSError {
reject("error", error.domain, error)
return
} catch {
reject("error", "Unexpected error. Verify that config is structured correctly.", error)
return
}
}
private func handleSdkCallbacks(idenfyController: IdenfyController, resolver resolve: @escaping RCTPromiseResolveBlock) {
idenfyController.handleIdenfyCallbacksWithManualResults(idenfyIdentificationResult: {
idenfyIdentificationResult
in
let response = NativeResponseToReactNativeResponseMapper.map(o: idenfyIdentificationResult)
resolve(response)
})
}
private func runFaceReauth(withConfig config: NSDictionary,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
do {
let authToken = GetSdkConfig.getAuthToken(config: config)
let idenfyController = IdenfyController.shared
let faceReauthenticationInitialization = FaceAuthenticationInitialization(authenticationToken: authToken, withImmediateRedirect: false)
idenfyController.initializeFaceAuthentication(faceAuthenticationInitialization: faceReauthenticationInitialization)
let idenfyVC = idenfyController.instantiateNavigationController()
idenfyVC.modalPresentationStyle = .fullScreen
UIApplication.shared.windows.first?.rootViewController?.present(idenfyVC, animated: true)
handleFaceReauthSdkCallbacks(idenfyController: idenfyController, resolver: resolve)
} catch let error as NSError {
reject("error", error.domain, error)
return
} catch {
reject("error", "Unexpected error. Verify that config is structured correctly.", error)
return
}
}
private func handleFaceReauthSdkCallbacks(idenfyController: IdenfyController, resolver resolve: @escaping RCTPromiseResolveBlock) {
idenfyController.handleIdenfyCallbacksForFaceAuthentication(faceAuthenticationResult: {
faceAuthenticationResult
in
let response = NativeResponseToReactNativeResponseMapper.mapFaceReauth(o: faceAuthenticationResult)
resolve(response)
})
}
}