Skip to content

Commit

Permalink
Update filepaths when files move (#174)
Browse files Browse the repository at this point in the history
* Update filepaths when files move

* Lints
  • Loading branch information
vanshg authored May 24, 2024
1 parent b2dedff commit e7f76fb
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 31 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

* Improved SmartSelfie Enrollment and Authentication times by moving to a synchronous API endpoint

#### Fixed

* Fixed a bug where invalid file paths were returned and retries did not work

## 10.1.3

#### Fixed

* Fix lottie SPM dependancy issues
* Fix Lottie SPM dependency issues

## 10.1.2

Expand Down
21 changes: 8 additions & 13 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
PODS:
- lottie-ios (4.4.3)
- netfox (1.21.0)
- Sentry (8.20.0):
- Sentry/Core (= 8.20.0)
- SentryPrivate (= 8.20.0)
- Sentry/Core (8.20.0):
- SentryPrivate (= 8.20.0)
- SentryPrivate (8.20.0)
- SmileID (10.1.3):
- Sentry (8.26.0):
- Sentry/Core (= 8.26.0)
- Sentry/Core (8.26.0)
- SmileID (10.1.4):
- lottie-ios (~> 4.4.2)
- Zip (~> 2.1.0)
- SwiftLint (0.54.0)
- SwiftLint (0.55.1)
- Zip (2.1.2)

DEPENDENCIES:
Expand All @@ -24,7 +21,6 @@ SPEC REPOS:
- lottie-ios
- netfox
- Sentry
- SentryPrivate
- SwiftLint
- Zip

Expand All @@ -35,10 +31,9 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
lottie-ios: fcb5e73e17ba4c983140b7d21095c834b3087418
netfox: 9d5cc727fe7576c4c7688a2504618a156b7d44b7
Sentry: a8d7b373b9f9868442b02a0c425192f693103cbf
SentryPrivate: 006b24af16828441f70e2ab6adf241bd0a8ad130
SmileID: 61ae985152b559099730bf211b74c9fbbcc4e516
SwiftLint: c1de071d9d08c8aba837545f6254315bc900e211
Sentry: 74a073c71c998117edb08f56f443c83570a31bed
SmileID: 7aec4c8dea152260533e55672ad7ba04658f6cd0
SwiftLint: 3fe909719babe5537c552ee8181c0031392be933
Zip: b3fef584b147b6e582b2256a9815c897d60ddc67

PODFILE CHECKSUM: 8f7be2cf75babf479684f1e21d344f4c640486be
Expand Down
2 changes: 0 additions & 2 deletions Example/SmileID.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-SmileID_Example/Pods-SmileID_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Sentry/Sentry.framework",
"${BUILT_PRODUCTS_DIR}/SentryPrivate/SentryPrivate.framework",
"${BUILT_PRODUCTS_DIR}/SmileID/SmileID.framework",
"${BUILT_PRODUCTS_DIR}/Zip/Zip.framework",
"${BUILT_PRODUCTS_DIR}/lottie-ios/Lottie.framework",
Expand All @@ -470,7 +469,6 @@
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Sentry.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SentryPrivate.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SmileID.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Zip.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Lottie.framework",
Expand Down
4 changes: 2 additions & 2 deletions SmileID.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = 'SmileID'
s.version = '10.1.3'
s.version = '10.1.4'
s.summary = 'The Official Smile Identity iOS SDK.'
s.homepage = 'https://docs.usesmileid.com/integration-options/mobile/ios-v10-beta'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Japhet' => 'japhet@usesmileid.com', 'Juma Allan' => 'juma@usesmileid.com', 'Vansh Gandhi' => 'vansh@usesmileid.com'}
s.source = { :git => "https://github.com/smileidentity/ios.git", :tag => "v10.1.3" }
s.source = { :git => "https://github.com/smileidentity/ios.git", :tag => "v10.1.4" }
s.ios.deployment_target = '13.0'
s.dependency 'Zip', '~> 2.1.0'
s.dependency 'lottie-ios', '~> 4.4.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {
didSubmitBiometricJob = true
do {
try LocalStorage.moveToSubmittedJobs(jobId: self.jobId)
self.selfieCaptureResultStore = SelfieCaptureResultStore(
selfie: try LocalStorage.getFileByType(
jobId: jobId,
fileType: FileType.selfie,
submitted: true
) ?? selfieCaptureResultStore.selfie,
livenessImages: try LocalStorage.getFilesByType(
jobId: jobId,
fileType: FileType.liveness,
submitted: true
) ?? selfieCaptureResultStore.livenessImages
)
} catch {
print("Error moving job to submitted directory: \(error)")
self.error = error
Expand All @@ -122,10 +134,24 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {
DispatchQueue.main.async { self.step = .processing(.success) }
} catch let error as SmileIDError {
do {
try LocalStorage.handleOfflineJobFailure(
let didMove = try LocalStorage.handleOfflineJobFailure(
jobId: self.jobId,
error: error
)
if didMove {
self.selfieCaptureResultStore = SelfieCaptureResultStore(
selfie: try LocalStorage.getFileByType(
jobId: jobId,
fileType: FileType.selfie,
submitted: true
) ?? selfieCaptureResultStore.selfie,
livenessImages: try LocalStorage.getFilesByType(
jobId: jobId,
fileType: FileType.liveness,
submitted: true
) ?? selfieCaptureResultStore.livenessImages
)
}
} catch {
print("Error moving job to submitted directory: \(error)")
self.error = error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ internal class IOrchestratedDocumentVerificationViewModel<T, U: JobResult>: Obse
didSubmitJob = true
do {
try LocalStorage.moveToSubmittedJobs(jobId: self.jobId)
self.selfieFile = try LocalStorage.getFileByType(
jobId: jobId,
fileType: FileType.selfie,
submitted: true
) ?? selfieFile
self.livenessFiles = try LocalStorage.getFilesByType(
jobId: jobId,
fileType: FileType.liveness,
submitted: true
) ?? []
} catch {
print("Error moving job to submitted directory: \(error)")
self.onError(error: error)
Expand All @@ -198,10 +208,22 @@ internal class IOrchestratedDocumentVerificationViewModel<T, U: JobResult>: Obse
DispatchQueue.main.async { self.step = .processing(.success) }
} catch let error as SmileIDError {
do {
try LocalStorage.handleOfflineJobFailure(
let didMove = try LocalStorage.handleOfflineJobFailure(
jobId: self.jobId,
error: error
)
if didMove {
self.selfieFile = try LocalStorage.getFileByType(
jobId: jobId,
fileType: FileType.selfie,
submitted: true
) ?? selfieFile
self.livenessFiles = try LocalStorage.getFilesByType(
jobId: jobId,
fileType: FileType.liveness,
submitted: true
) ?? []
}
} catch {
print("Error moving job to submitted directory: \(error)")
self.onError(error: error)
Expand Down
24 changes: 17 additions & 7 deletions Sources/SmileID/Classes/Helpers/LocalStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,19 @@ public class LocalStorage {

static func getFileByType(
jobId: String,
fileType: FileType
fileType: FileType,
submitted: Bool = false
) throws -> URL? {
let contents = try getDirectoryContents(jobId: jobId)
let contents = try getDirectoryContents(jobId: jobId, submitted: submitted)
return contents.first(where: { $0.lastPathComponent.contains(fileType.name) })!
}

static func getFilesByType(
jobId: String,
fileType: FileType
fileType: FileType,
submitted: Bool = false
) throws -> [URL]? {
let contents = try getDirectoryContents(jobId: jobId)
let contents = try getDirectoryContents(jobId: jobId, submitted: submitted)
return contents.filter { $0.lastPathComponent.contains(fileType.name) }
}

Expand Down Expand Up @@ -236,9 +238,11 @@ public class LocalStorage {
}

private static func getDirectoryContents(
jobId: String
jobId: String,
submitted: Bool = false
) throws -> [URL] {
let folderPathURL = try unsubmittedJobDirectory.appendingPathComponent(jobId)
let baseDirectory = try submitted ? submittedJobDirectory : unsubmittedJobDirectory
let folderPathURL = baseDirectory.appendingPathComponent(jobId)
return try fileManager.contentsOfDirectory(at: folderPathURL, includingPropertiesForKeys: nil)
}

Expand Down Expand Up @@ -270,13 +274,19 @@ public class LocalStorage {
try fileManager.moveItem(at: unsubmittedFileDirectory, to: submittedFileDirectory)
}

/// Moves files from unsubmitted to submitted when not in Offline Mode, or if it was not a
/// network error
/// Returns: true if files were moved
static func handleOfflineJobFailure(
jobId: String,
error: SmileIDError
) throws {
) throws -> Bool {
var didMove = false
if !(SmileID.allowOfflineMode && isNetworkFailure(error: error)) {
try LocalStorage.moveToSubmittedJobs(jobId: jobId)
didMove = true
}
return didMove
}

static func isNetworkFailure(
Expand Down
24 changes: 23 additions & 1 deletion Sources/SmileID/Classes/SelfieCapture/SelfieViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,39 @@ public class SelfieViewModel: ObservableObject, ARKitSmileDelegate {
apiResponse = response
do {
try LocalStorage.moveToSubmittedJobs(jobId: self.jobId)
self.selfieImage = try LocalStorage.getFileByType(
jobId: jobId,
fileType: FileType.selfie,
submitted: true
)
self.livenessImages = try LocalStorage.getFilesByType(
jobId: jobId,
fileType: FileType.liveness,
submitted: true
) ?? []
} catch {
print("Error moving job to submitted directory: \(error)")
self.error = error
}
DispatchQueue.main.async { self.processingState = .success }
} catch let error as SmileIDError {
do {
try LocalStorage.handleOfflineJobFailure(
let didMove = try LocalStorage.handleOfflineJobFailure(
jobId: self.jobId,
error: error
)
if didMove {
self.selfieImage = try LocalStorage.getFileByType(
jobId: jobId,
fileType: FileType.selfie,
submitted: true
)
self.livenessImages = try LocalStorage.getFilesByType(
jobId: jobId,
fileType: FileType.liveness,
submitted: true
) ?? []
}
} catch {
print("Error moving job to submitted directory: \(error)")
self.error = error
Expand Down
7 changes: 4 additions & 3 deletions Sources/SmileID/Classes/SmileID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftUI
import UIKit

public class SmileID {
public static let version = "10.1.3"
public static let version = "10.1.4"
@Injected var injectedApi: SmileIDServiceable
public static var configuration: Config { config }

Expand Down Expand Up @@ -142,7 +142,8 @@ public class SmileID {
let authResponse = try await SmileID.api.authenticate(request: authRequest).async()
let prepUploadRequest = PrepUploadRequest(
partnerParams: authResponse.partnerParams.copy(extras: prepUploadFile.partnerParams.extras),
allowNewEnroll: String(prepUploadFile.allowNewEnroll), // TODO: - Fix when Michael changes this to boolean
// TODO: - Fix when Michael changes this to boolean
allowNewEnroll: String(prepUploadFile.allowNewEnroll),
timestamp: authResponse.timestamp,
signature: authResponse.signature
)
Expand All @@ -151,7 +152,7 @@ public class SmileID {
LocalStorage.getFileByType(jobId: jobId, fileType: FileType.selfie),
LocalStorage.getFileByType(jobId: jobId, fileType: FileType.documentFront),
LocalStorage.getFileByType(jobId: jobId, fileType: FileType.documentBack),
LocalStorage.getInfoJsonFile(jobId: jobId),
LocalStorage.getInfoJsonFile(jobId: jobId)
].compactMap { $0 }
let zipUrl = try LocalStorage.zipFiles(at: allFiles)
zip = try Data(contentsOf: zipUrl)
Expand Down

0 comments on commit e7f76fb

Please sign in to comment.