@smile_identity/react-native 10.1.12 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/android/src/main/java/com/smileidentity/react/results/DocumentCaptureResult.kt +12 -0
  2. package/android/src/main/java/com/smileidentity/react/results/SmartSelfieCaptureResult.kt +11 -0
  3. package/android/src/main/java/com/smileidentity/react/utils/DocumentCaptureResultAdapter.kt +46 -2
  4. package/android/src/main/java/com/smileidentity/react/utils/SelfieCaptureResultAdapter.kt +28 -17
  5. package/android/src/main/java/com/smileidentity/react/views/SmileIDBiometricKYCView.kt +26 -15
  6. package/android/src/main/java/com/smileidentity/react/views/SmileIDDocumentCaptureView.kt +1 -8
  7. package/android/src/main/java/com/smileidentity/react/views/SmileIDDocumentVerificationView.kt +28 -15
  8. package/android/src/main/java/com/smileidentity/react/views/SmileIDEnhancedDocumentVerificationView.kt +28 -15
  9. package/android/src/main/java/com/smileidentity/react/views/SmileIDSmartSelfieAuthenticationView.kt +26 -16
  10. package/android/src/main/java/com/smileidentity/react/views/SmileIDSmartSelfieCaptureView.kt +1 -5
  11. package/android/src/main/java/com/smileidentity/react/views/SmileIDSmartSelfieEnrollmentView.kt +26 -16
  12. package/ios/Utils/FileUtils.swift +24 -0
  13. package/ios/View/SmileIDBiometricKYCView.swift +54 -51
  14. package/ios/View/SmileIDDocumentVerificationView.swift +50 -47
  15. package/ios/View/SmileIDEnhancedDocumentVerificationView.swift +49 -47
  16. package/ios/View/SmileIDSmartSelfieAuthView.swift +35 -33
  17. package/ios/View/SmileIDSmartSelfieCaptureView.swift +4 -41
  18. package/ios/View/SmileIDSmartSelfieEnrollmentView.swift +35 -33
  19. package/lib/commonjs/types.js.map +1 -1
  20. package/lib/module/types.js.map +1 -1
  21. package/lib/typescript/types.d.ts +4 -2
  22. package/lib/typescript/types.d.ts.map +1 -1
  23. package/package.json +1 -1
  24. package/react-native-smile-id.podspec +1 -1
  25. package/src/types.ts +10 -2
@@ -2,59 +2,62 @@ import Foundation
2
2
  import SmileID
3
3
  import SwiftUI
4
4
 
5
- struct SmileIDBiometricKYCView: View {
6
- @ObservedObject var product : SmileIDProductModel
7
- var body: some View{
8
- NavigationView {
9
- if let idInfo = product.idInfo {
10
- SmileID.biometricKycScreen(
11
- idInfo: idInfo, // already validated in the SmileIDBiometricKYCViewManager
12
- userId: product.userId ?? generateUserId(),
13
- jobId: product.jobId ?? generateJobId(),
14
- allowNewEnroll: product.allowNewEnroll,
15
- allowAgentMode: product.allowAgentMode,
16
- showAttribution: product.showAttribution,
17
- showInstructions: product.showInstructions,
18
- extraPartnerParams: product.extraPartnerParams as [String: String],
19
- delegate: self
20
- )
21
- } else {
22
- // This exists for debugging purposes and will show in extreme cases
23
- // when the params were not set NB: setParams in the viewmanager will always
24
- // return an error if the required data is missing
25
- Text("An error has occured")
26
- }
27
- }.navigationViewStyle(StackNavigationViewStyle())
28
- }
5
+ struct SmileIDBiometricKYCView: View ,SmileIDFileUtilsProtocol {
6
+ var fileManager: FileManager = Foundation.FileManager.default
7
+ @ObservedObject var product : SmileIDProductModel
8
+ var body: some View{
9
+ NavigationView {
10
+ if let idInfo = product.idInfo {
11
+ SmileID.biometricKycScreen(
12
+ idInfo: idInfo, // already validated in the SmileIDBiometricKYCViewManager
13
+ userId: product.userId ?? generateUserId(),
14
+ jobId: product.jobId ?? generateJobId(),
15
+ allowNewEnroll: product.allowNewEnroll,
16
+ allowAgentMode: product.allowAgentMode,
17
+ showAttribution: product.showAttribution,
18
+ showInstructions: product.showInstructions,
19
+ extraPartnerParams: product.extraPartnerParams as [String: String],
20
+ delegate: self
21
+ )
22
+ } else {
23
+ // This exists for debugging purposes and will show in extreme cases
24
+ // when the params were not set NB: setParams in the viewmanager will always
25
+ // return an error if the required data is missing
26
+ Text("An error has occured")
27
+ }
28
+ }.navigationViewStyle(StackNavigationViewStyle())
29
+ }
29
30
  }
30
31
 
31
32
  extension SmileIDBiometricKYCView: BiometricKycResultDelegate {
32
- func didSucceed(selfieImage: URL, livenessImages: [URL], didSubmitBiometricJob: Bool) {
33
-
34
- let params: [String: Any] = [
35
- "selfieFile": selfieImage.absoluteString,
36
- "livenessFiles": livenessImages,
37
- "didSubmitBiometricKycJob": didSubmitBiometricJob,
38
- ]
39
-
40
- guard let jsonData = try? JSONSerialization.data(withJSONObject: params.toJSONCompatibleDictionary(), options: .prettyPrinted) else {
41
- product.onResult?(["error": SmileIDError.unknown("SmileIDBiometricKYCView encoding error")])
42
- return
43
- }
44
- product.onResult?(["result": String(data: jsonData, encoding: .utf8)!])
45
- }
46
-
47
- func didSucceed(
48
- selfieImage _: URL,
49
- livenessImages _: [URL],
50
- jobStatusResponse: BiometricKycJobStatusResponse
51
- ) {
52
- let encoder = JSONEncoder()
53
- let jsonData = try! encoder.encode(jobStatusResponse)
54
- product.onResult?(["result": String(data: jsonData, encoding: .utf8)!])
55
- }
56
-
57
- func didError(error: Error) {
58
- product.onResult?(["error": error.localizedDescription])
33
+ func didSucceed(selfieImage: URL, livenessImages: [URL], didSubmitBiometricJob: Bool) {
34
+
35
+ let params: [String: Any] = [
36
+ "selfieFile": getFilePath(fileName: selfieImage.absoluteString),
37
+ "livenessFiles": livenessImages.map {
38
+ getFilePath(fileName: $0.absoluteString)
39
+ },
40
+ "didSubmitBiometricKycJob": didSubmitBiometricJob,
41
+ ]
42
+
43
+ guard let jsonData = try? JSONSerialization.data(withJSONObject: params.toJSONCompatibleDictionary(), options: .prettyPrinted) else {
44
+ product.onResult?(["error": SmileIDError.unknown("SmileIDBiometricKYCView encoding error")])
45
+ return
59
46
  }
47
+ product.onResult?(["result": String(data: jsonData, encoding: .utf8)!])
48
+ }
49
+
50
+ func didSucceed(
51
+ selfieImage _: URL,
52
+ livenessImages _: [URL],
53
+ jobStatusResponse: BiometricKycJobStatusResponse
54
+ ) {
55
+ let encoder = JSONEncoder()
56
+ let jsonData = try! encoder.encode(jobStatusResponse)
57
+ product.onResult?(["result": String(data: jsonData, encoding: .utf8)!])
58
+ }
59
+
60
+ func didError(error: Error) {
61
+ product.onResult?(["error": error.localizedDescription])
62
+ }
60
63
  }
@@ -2,56 +2,59 @@ import Foundation
2
2
  import SmileID
3
3
  import SwiftUI
4
4
 
5
- struct SmileIDDocumentVerificationView: View {
6
- @ObservedObject var product : SmileIDProductModel
7
- var body : some View {
8
- AnyView(NavigationView {
9
- if let countryCode = product.countryCode {
10
- SmileID.documentVerificationScreen(
11
- userId: product.userId ?? generateUserId(),
12
- jobId: product.jobId ?? generateJobId(),
13
- allowNewEnroll: product.allowNewEnroll,
14
- countryCode: countryCode, // already validated in SmileIDDocumentVerificationViewManager
15
- documentType: product.documentType,
16
- idAspectRatio: product.idAspectRatio,
17
- bypassSelfieCaptureWithFile: product.bypassSelfieCaptureWithFilePath,
18
- captureBothSides: product.captureBothSides,
19
- allowAgentMode: product.allowAgentMode,
20
- allowGalleryUpload: product.allowGalleryUpload,
21
- showInstructions: product.showInstructions,
22
- showAttribution: product.showAttribution,
23
- extraPartnerParams: product.extraPartnerParams as [String: String],
24
- delegate: self
25
- )
26
- } else {
27
- // This exists for debugging purposes and will show in extreme cases
28
- // when the params were not set NB: setParams in the viewmanager will always
29
- // return an error if the required data is missing
30
- Text("An error has occured")
31
- }
32
- }.navigationViewStyle(StackNavigationViewStyle()))
33
- }
5
+ struct SmileIDDocumentVerificationView: View ,SmileIDFileUtilsProtocol {
6
+ var fileManager: FileManager = Foundation.FileManager.default
7
+ @ObservedObject var product : SmileIDProductModel
8
+ var body : some View {
9
+ AnyView(NavigationView {
10
+ if let countryCode = product.countryCode {
11
+ SmileID.documentVerificationScreen(
12
+ userId: product.userId ?? generateUserId(),
13
+ jobId: product.jobId ?? generateJobId(),
14
+ allowNewEnroll: product.allowNewEnroll,
15
+ countryCode: countryCode, // already validated in SmileIDDocumentVerificationViewManager
16
+ documentType: product.documentType,
17
+ idAspectRatio: product.idAspectRatio,
18
+ bypassSelfieCaptureWithFile: product.bypassSelfieCaptureWithFilePath,
19
+ captureBothSides: product.captureBothSides,
20
+ allowAgentMode: product.allowAgentMode,
21
+ allowGalleryUpload: product.allowGalleryUpload,
22
+ showInstructions: product.showInstructions,
23
+ showAttribution: product.showAttribution,
24
+ extraPartnerParams: product.extraPartnerParams as [String: String],
25
+ delegate: self
26
+ )
27
+ } else {
28
+ // This exists for debugging purposes and will show in extreme cases
29
+ // when the params were not set NB: setParams in the viewmanager will always
30
+ // return an error if the required data is missing
31
+ Text("An error has occured")
32
+ }
33
+ }.navigationViewStyle(StackNavigationViewStyle()))
34
+ }
34
35
  }
35
36
 
36
37
  extension SmileIDDocumentVerificationView: DocumentVerificationResultDelegate {
37
- func didSucceed(selfie: URL, documentFrontImage: URL, documentBackImage: URL?, didSubmitDocumentVerificationJob: Bool) {
38
- var params: [String: Any] = [
39
- "selfieFile": selfie.absoluteString,
40
- "documentFrontFile": documentFrontImage.absoluteString,
41
- "didSubmitDocumentVerificationJob": didSubmitDocumentVerificationJob
42
- ]
43
- if let documentBackImage = documentBackImage {
44
- params["documentBackFile"] = documentBackImage.absoluteString
45
- }
46
-
47
- guard let jsonData = try? JSONSerialization.data(withJSONObject: params.toJSONCompatibleDictionary(), options: .prettyPrinted) else {
48
- product.onResult?(["error": SmileIDError.unknown("SmileIDDocumentVerificationView encoding error")])
49
- return
50
- }
51
- product.onResult?(["result": String(data: jsonData, encoding: .utf8)!])
38
+ func didSucceed(selfie: URL, documentFrontImage: URL, documentBackImage: URL?, didSubmitDocumentVerificationJob: Bool) {
39
+
40
+ var params: [String: Any] = [
41
+ "selfieFile": getFilePath(fileName: selfie.absoluteString),
42
+ "documentFrontFile": getFilePath(fileName: documentFrontImage.absoluteString),
43
+ "didSubmitDocumentVerificationJob": didSubmitDocumentVerificationJob
44
+ ]
45
+
46
+ if let documentBackImage = documentBackImage {
47
+ params["documentBackFile"] = getFilePath(fileName: documentBackImage.absoluteString)
52
48
  }
53
-
54
- func didError(error: Error) {
55
- product.onResult?(["error": error.localizedDescription])
49
+
50
+ guard let jsonData = try? JSONSerialization.data(withJSONObject: params.toJSONCompatibleDictionary(), options: .prettyPrinted) else {
51
+ product.onResult?(["error": SmileIDError.unknown("SmileIDDocumentVerificationView encoding error")])
52
+ return
56
53
  }
54
+ product.onResult?(["result": String(data: jsonData, encoding: .utf8)!])
55
+ }
56
+
57
+ func didError(error: Error) {
58
+ product.onResult?(["error": error.localizedDescription])
59
+ }
57
60
  }
@@ -2,56 +2,58 @@ import Foundation
2
2
  import SmileID
3
3
  import SwiftUI
4
4
 
5
- struct SmileIDEnhancedDocumentVerificationView: View {
6
- @ObservedObject var product : SmileIDProductModel
7
- var body: some View {
8
- NavigationView {
9
- if let countryCode = product.countryCode {
10
- SmileID.enhancedDocumentVerificationScreen(
11
- userId: product.userId ?? generateUserId(),
12
- jobId: product.jobId ?? generateJobId(),
13
- allowNewEnroll: product.allowNewEnroll,
14
- countryCode: countryCode, // already validated in the view manager
15
- documentType: product.documentType,
16
- idAspectRatio: product.idAspectRatio,
17
- bypassSelfieCaptureWithFile: product.bypassSelfieCaptureWithFilePath,
18
- captureBothSides: product.captureBothSides,
19
- allowAgentMode: product.allowAgentMode,
20
- allowGalleryUpload: product.allowGalleryUpload,
21
- showInstructions: product.showInstructions,
22
- showAttribution: product.showAttribution,
23
- extraPartnerParams: product.extraPartnerParams as [String: String],
24
- delegate: self
25
- )
26
- } else {
27
- // This exists for debugging purposes and will show in extreme cases
28
- // when the params were not set NB: setParams in the viewmanager will always
29
- // return an error if the required data is missing
30
- Text("An error has occured")
31
- }
32
- }.navigationViewStyle(StackNavigationViewStyle())
33
- }
5
+ struct SmileIDEnhancedDocumentVerificationView: View,SmileIDFileUtilsProtocol {
6
+ var fileManager: FileManager = Foundation.FileManager.default
7
+ @ObservedObject var product : SmileIDProductModel
8
+ var body: some View {
9
+ NavigationView {
10
+ if let countryCode = product.countryCode {
11
+ SmileID.enhancedDocumentVerificationScreen(
12
+ userId: product.userId ?? generateUserId(),
13
+ jobId: product.jobId ?? generateJobId(),
14
+ allowNewEnroll: product.allowNewEnroll,
15
+ countryCode: countryCode, // already validated in the view manager
16
+ documentType: product.documentType,
17
+ idAspectRatio: product.idAspectRatio,
18
+ bypassSelfieCaptureWithFile: product.bypassSelfieCaptureWithFilePath,
19
+ captureBothSides: product.captureBothSides,
20
+ allowAgentMode: product.allowAgentMode,
21
+ allowGalleryUpload: product.allowGalleryUpload,
22
+ showInstructions: product.showInstructions,
23
+ showAttribution: product.showAttribution,
24
+ extraPartnerParams: product.extraPartnerParams as [String: String],
25
+ delegate: self
26
+ )
27
+ } else {
28
+ // This exists for debugging purposes and will show in extreme cases
29
+ // when the params were not set NB: setParams in the viewmanager will always
30
+ // return an error if the required data is missing
31
+ Text("An error has occured")
32
+ }
33
+ }.navigationViewStyle(StackNavigationViewStyle())
34
+ }
34
35
  }
35
36
 
36
37
  extension SmileIDEnhancedDocumentVerificationView: EnhancedDocumentVerificationResultDelegate {
37
- func didSucceed(selfie: URL, documentFrontImage: URL, documentBackImage: URL?, didSubmitEnhancedDocVJob: Bool) {
38
- var params: [String: Any] = [
39
- "selfieFile": selfie.absoluteString,
40
- "documentFrontFile": documentFrontImage.absoluteString,
41
- "didSubmitEnhancedDocVJob": didSubmitEnhancedDocVJob
42
- ]
43
- if let documentBackImage = documentBackImage {
44
- params["documentBackFile"] = documentBackImage.absoluteString
45
- }
46
-
47
- guard let jsonData = try? JSONSerialization.data(withJSONObject: params.toJSONCompatibleDictionary(), options: .prettyPrinted) else {
48
- product.onResult?(["error": SmileIDError.unknown("SmileIDEnhancedDocumentVerificationView encoding error")])
49
- return
50
- }
51
- product.onResult?(["result": String(data: jsonData, encoding: .utf8)!])
38
+ func didSucceed(selfie: URL, documentFrontImage: URL, documentBackImage: URL?, didSubmitEnhancedDocVJob: Bool) {
39
+ var params: [String: Any] = [
40
+ "selfieFile": getFilePath(fileName: selfie.absoluteString),
41
+ "documentFrontFile": getFilePath(fileName: documentFrontImage.absoluteString),
42
+ "didSubmitEnhancedDocVJob": didSubmitEnhancedDocVJob
43
+ ]
44
+
45
+ if let documentBackImage = documentBackImage {
46
+ params["documentBackFile"] = getFilePath(fileName: documentBackImage.absoluteString)
52
47
  }
53
-
54
- func didError(error: Error) {
55
- product.onResult?(["error": error.localizedDescription])
48
+
49
+ guard let jsonData = try? JSONSerialization.data(withJSONObject: params.toJSONCompatibleDictionary(), options: .prettyPrinted) else {
50
+ product.onResult?(["error": SmileIDError.unknown("SmileIDEnhancedDocumentVerificationView encoding error")])
51
+ return
56
52
  }
53
+ product.onResult?(["result": String(data: jsonData, encoding: .utf8)!])
54
+ }
55
+
56
+ func didError(error: Error) {
57
+ product.onResult?(["error": error.localizedDescription])
58
+ }
57
59
  }
@@ -2,42 +2,44 @@ import Foundation
2
2
  import SmileID
3
3
  import SwiftUI
4
4
 
5
- struct SmileIDSmartSelfieAuthView: View {
6
- @ObservedObject var product : SmileIDProductModel
7
- var body: some View {
8
- NavigationView {
9
- SmileID.smartSelfieAuthenticationScreen(
10
- userId: product.userId ?? generateUserId(),
11
- jobId: product.jobId ?? generateJobId(),
12
- allowNewEnroll: product.allowNewEnroll,
13
- allowAgentMode: product.allowAgentMode,
14
- showAttribution: product.showAttribution,
15
- showInstructions: product.showInstructions,
16
- extraPartnerParams: product.extraPartnerParams as [String: String],
17
- delegate: self
18
- )
19
- }.navigationViewStyle(StackNavigationViewStyle())
20
- }
5
+ struct SmileIDSmartSelfieAuthView: View,SmileIDFileUtilsProtocol {
6
+ var fileManager: FileManager = Foundation.FileManager.default
7
+ @ObservedObject var product : SmileIDProductModel
8
+ var body: some View {
9
+ NavigationView {
10
+ SmileID.smartSelfieAuthenticationScreen(
11
+ userId: product.userId ?? generateUserId(),
12
+ allowNewEnroll: product.allowNewEnroll,
13
+ allowAgentMode: product.allowAgentMode,
14
+ showAttribution: product.showAttribution,
15
+ showInstructions: product.showInstructions,
16
+ extraPartnerParams: product.extraPartnerParams as [String: String],
17
+ delegate: self
18
+ )
19
+ }.navigationViewStyle(StackNavigationViewStyle())
20
+ }
21
21
  }
22
22
 
23
23
  extension SmileIDSmartSelfieAuthView: SmartSelfieResultDelegate {
24
- func didSucceed(selfieImage: URL, livenessImages: [URL], apiResponse: SmartSelfieResponse?) {
25
- var params: [String: Any] = [
26
- "selfieFile": selfieImage.absoluteString,
27
- "livenessFiles": livenessImages,
28
- ]
29
- if let apiResponse = apiResponse {
30
- params["apiResponse"] = apiResponse
31
- }
32
-
33
- guard let jsonData = try? JSONSerialization.data(withJSONObject: params.toJSONCompatibleDictionary(), options: .prettyPrinted) else {
34
- product.onResult?(["error": SmileIDError.unknown("SmileIDSmartSelfieAuthView encoding error")])
35
- return
36
- }
37
- product.onResult?(["result": String(data: jsonData, encoding: .utf8)!])
24
+ func didSucceed(selfieImage: URL, livenessImages: [URL], apiResponse: SmartSelfieResponse?) {
25
+ var params: [String: Any] = [
26
+ "selfieFile": getFilePath(fileName: selfieImage.absoluteString),
27
+ "livenessFiles": livenessImages.map {
28
+ getFilePath(fileName: $0.absoluteString)
29
+ }
30
+ ]
31
+ if let apiResponse = apiResponse {
32
+ params["apiResponse"] = apiResponse
38
33
  }
39
-
40
- func didError(error: Error) {
41
- product.onResult?(["error": error.localizedDescription])
34
+
35
+ guard let jsonData = try? JSONSerialization.data(withJSONObject: params.toJSONCompatibleDictionary(), options: .prettyPrinted) else {
36
+ product.onResult?(["error": SmileIDError.unknown("SmileIDSmartSelfieAuthView encoding error")])
37
+ return
42
38
  }
39
+ product.onResult?(["result": String(data: jsonData, encoding: .utf8)!])
40
+ }
41
+
42
+ func didError(error: Error) {
43
+ product.onResult?(["error": error.localizedDescription])
44
+ }
43
45
  }
@@ -3,12 +3,11 @@ import SmileID
3
3
  import SwiftUI
4
4
 
5
5
 
6
- struct SmileIDSmartSelfieCaptureView: View {
6
+ struct SmileIDSmartSelfieCaptureView: View, SmileIDFileUtilsProtocol {
7
+ var fileManager: FileManager = Foundation.FileManager.default
7
8
  @ObservedObject var viewModel: SelfieViewModel
8
9
  @ObservedObject var product: SmileIDProductModel
9
10
  @State private var acknowledgedInstructions = false
10
- static let shared = FileManager()
11
- private let fileManager = Foundation.FileManager.default
12
11
 
13
12
  var body: some View {
14
13
  NavigationView {
@@ -52,7 +51,7 @@ struct SmileIDSmartSelfieCaptureView: View {
52
51
 
53
52
  extension SmileIDSmartSelfieCaptureView: SmartSelfieResultDelegate {
54
53
  func didSucceed(selfieImage: URL, livenessImages: [URL], apiResponse: SmartSelfieResponse?) {
55
- var params: [String: Any] = [
54
+ let params: [String: Any] = [
56
55
  "selfieFile": getFilePath(fileName: selfieImage.absoluteString),
57
56
  "livenessFiles": livenessImages.map {
58
57
  getFilePath(fileName: $0.absoluteString)
@@ -60,7 +59,7 @@ extension SmileIDSmartSelfieCaptureView: SmartSelfieResultDelegate {
60
59
  ]
61
60
 
62
61
  guard let jsonData = try? JSONSerialization.data(withJSONObject: params.toJSONCompatibleDictionary(), options: .prettyPrinted) else {
63
- product.onResult?(["error": SmileIDError.unknown("SmileIDSmartSelfieEnrollmentView encoding error")])
62
+ product.onResult?(["error": SmileIDError.unknown("SmileIDSmartSelfieCaptureView encoding error")])
64
63
  return
65
64
  }
66
65
  product.onResult?(["result": String(data: jsonData, encoding: .utf8)!])
@@ -69,40 +68,4 @@ extension SmileIDSmartSelfieCaptureView: SmartSelfieResultDelegate {
69
68
  func didError(error: Error) {
70
69
  product.onResult?(["error": error.localizedDescription])
71
70
  }
72
-
73
- func getSmileIDDirectory() -> String? {
74
- guard let documentsDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else {
75
- print("Unable to access documents directory")
76
- return nil
77
- }
78
-
79
- let smileIDDirectory = documentsDirectory.appendingPathComponent("SmileID")
80
- return smileIDDirectory.absoluteURL.absoluteString
81
- }
82
-
83
- func createSmileIDDirectoryIfNeeded() -> Bool {
84
- guard let smileIDDirectory = getSmileIDDirectory() else {
85
- return false
86
- }
87
-
88
- if !fileManager.fileExists(atPath: smileIDDirectory) {
89
- do {
90
- try fileManager.createDirectory(atPath: smileIDDirectory, withIntermediateDirectories: true, attributes: nil)
91
- return true
92
- } catch {
93
- print("Error creating SmileID directory: \(error)")
94
- return false
95
- }
96
- }
97
-
98
- return true
99
- }
100
-
101
- func getFilePath(fileName: String) -> String? {
102
- guard let smileIDDirectory = getSmileIDDirectory() else {
103
- return nil
104
- }
105
-
106
- return (smileIDDirectory as NSString).appendingPathComponent(fileName)
107
- }
108
71
  }
@@ -2,42 +2,44 @@ import Foundation
2
2
  import SmileID
3
3
  import SwiftUI
4
4
 
5
- struct SmileIDSmartSelfieEnrollmentView: View {
6
- @ObservedObject var product : SmileIDProductModel
7
- var body: some View {
8
- NavigationView {
9
- SmileID.smartSelfieEnrollmentScreen(
10
- userId: product.userId ?? generateUserId(),
11
- jobId: product.jobId ?? generateJobId(),
12
- allowNewEnroll: product.allowNewEnroll,
13
- allowAgentMode: product.allowAgentMode,
14
- showAttribution: product.showAttribution,
15
- showInstructions: product.showInstructions,
16
- extraPartnerParams: product.extraPartnerParams as [String: String],
17
- delegate: self
18
- )
19
- }.navigationViewStyle(StackNavigationViewStyle())
20
- }
5
+ struct SmileIDSmartSelfieEnrollmentView: View,SmileIDFileUtilsProtocol {
6
+ var fileManager: FileManager = Foundation.FileManager.default
7
+ @ObservedObject var product : SmileIDProductModel
8
+ var body: some View {
9
+ NavigationView {
10
+ SmileID.smartSelfieEnrollmentScreen(
11
+ userId: product.userId ?? generateUserId(),
12
+ allowNewEnroll: product.allowNewEnroll,
13
+ allowAgentMode: product.allowAgentMode,
14
+ showAttribution: product.showAttribution,
15
+ showInstructions: product.showInstructions,
16
+ extraPartnerParams: product.extraPartnerParams as [String: String],
17
+ delegate: self
18
+ )
19
+ }.navigationViewStyle(StackNavigationViewStyle())
20
+ }
21
21
  }
22
22
 
23
23
  extension SmileIDSmartSelfieEnrollmentView: SmartSelfieResultDelegate {
24
- func didSucceed(selfieImage: URL, livenessImages: [URL], apiResponse: SmartSelfieResponse?) {
25
- var params: [String: Any] = [
26
- "selfieFile": selfieImage.absoluteString,
27
- "livenessFiles": livenessImages,
28
- ]
29
- if let apiResponse = apiResponse {
30
- params["apiResponse"] = apiResponse
31
- }
32
-
33
- guard let jsonData = try? JSONSerialization.data(withJSONObject: params.toJSONCompatibleDictionary(), options: .prettyPrinted) else {
34
- product.onResult?(["error": SmileIDError.unknown("SmileIDSmartSelfieEnrollmentView encoding error")])
35
- return
36
- }
37
- product.onResult?(["result": String(data: jsonData, encoding: .utf8)!])
24
+ func didSucceed(selfieImage: URL, livenessImages: [URL], apiResponse: SmartSelfieResponse?) {
25
+ var params: [String: Any] = [
26
+ "selfieFile": getFilePath(fileName: selfieImage.absoluteString),
27
+ "livenessFiles": livenessImages.map {
28
+ getFilePath(fileName: $0.absoluteString)
29
+ },
30
+ ]
31
+ if let apiResponse = apiResponse {
32
+ params["apiResponse"] = apiResponse
38
33
  }
39
-
40
- func didError(error: Error) {
41
- product.onResult?(["error": error.localizedDescription])
34
+
35
+ guard let jsonData = try? JSONSerialization.data(withJSONObject: params.toJSONCompatibleDictionary(), options: .prettyPrinted) else {
36
+ product.onResult?(["error": SmileIDError.unknown("SmileIDSmartSelfieEnrollmentView encoding error")])
37
+ return
42
38
  }
39
+ product.onResult?(["result": String(data: jsonData, encoding: .utf8)!])
40
+ }
41
+
42
+ func didError(error: Error) {
43
+ product.onResult?(["error": error.localizedDescription])
44
+ }
43
45
  }