From c61c844d71447922b8ec6d6858dd6454d6323dd9 Mon Sep 17 00:00:00 2001 From: JNdhlovu Date: Thu, 7 Nov 2024 12:56:00 +0200 Subject: [PATCH] feat: clear files on retry and on start capture (#251) * feat: clear files on retry and on start capture * feat: clear files on retry and on start capture * feat: rename cleanup func --- CHANGELOG.md | 4 ++++ Example/Podfile.lock | 4 ++-- SmileID.podspec | 4 ++-- .../Classes/Helpers/LocalStorage.swift | 20 +++++++++++++++++++ .../SelfieCapture/SelfieViewModel.swift | 13 +++++++++++- Sources/SmileID/Classes/SmileID.swift | 2 +- 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9644ab5..cb0024d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes +## 10.2.16 +### Fixed +* Clear images on retry or start capture with the same jobId + ## 10.2.15 ### Changed diff --git a/Example/Podfile.lock b/Example/Podfile.lock index a2d6a64b..2f4db733 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -12,7 +12,7 @@ PODS: - Sentry (8.36.0): - Sentry/Core (= 8.36.0) - Sentry/Core (8.36.0) - - SmileID (10.2.15): + - SmileID (10.2.16): - FingerprintJS - lottie-ios (~> 4.4.2) - ZIPFoundation (~> 0.9) @@ -51,7 +51,7 @@ SPEC CHECKSUMS: lottie-ios: fcb5e73e17ba4c983140b7d21095c834b3087418 netfox: 9d5cc727fe7576c4c7688a2504618a156b7d44b7 Sentry: f8374b5415bc38dfb5645941b3ae31230fbeae57 - SmileID: 0ce57af077a6d201d382b67209f9d8742db6c97b + SmileID: 3c6d3101c7da84fe9acc36c10d2a189192f00d13 SwiftLint: 3fe909719babe5537c552ee8181c0031392be933 ZIPFoundation: b8c29ea7ae353b309bc810586181fd073cb3312c diff --git a/SmileID.podspec b/SmileID.podspec index a3e6598d..774f949e 100644 --- a/SmileID.podspec +++ b/SmileID.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = 'SmileID' - s.version = '10.2.15' + s.version = '10.2.16' 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.2.14" } + s.source = { :git => "https://github.com/smileidentity/ios.git", :tag => "v10.2.16" } s.ios.deployment_target = '13.0' s.dependency 'ZIPFoundation', '~> 0.9' s.dependency 'FingerprintJS' diff --git a/Sources/SmileID/Classes/Helpers/LocalStorage.swift b/Sources/SmileID/Classes/Helpers/LocalStorage.swift index 5f5b7a1e..0b9bc7ab 100644 --- a/Sources/SmileID/Classes/Helpers/LocalStorage.swift +++ b/Sources/SmileID/Classes/Helpers/LocalStorage.swift @@ -356,6 +356,26 @@ public class LocalStorage { try fileManager.removeItem(atPath: defaultDirectory.relativePath) } } + + static func deleteLivenessAndSelfieFiles(at jobIds: [String]) throws { + func deleteMatchingFiles(in directory: URL) throws { + let contents = try FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: nil) + try contents.forEach { url in + let filename = url.lastPathComponent + if filename.starts(with: "si_liveness_") || filename.starts(with: "si_selfie_") { + try delete(at: url) + } + } + } + + try jobIds.forEach { jobId in + let unsubmittedJob = try unsubmittedJobDirectory.appendingPathComponent(jobId) + try deleteMatchingFiles(in: unsubmittedJob) + + let submittedJob = try submittedJobDirectory.appendingPathComponent(jobId) + try deleteMatchingFiles(in: submittedJob) + } + } } public extension Date { diff --git a/Sources/SmileID/Classes/SelfieCapture/SelfieViewModel.swift b/Sources/SmileID/Classes/SelfieCapture/SelfieViewModel.swift index 94b601fd..c62ef7b6 100644 --- a/Sources/SmileID/Classes/SelfieCapture/SelfieViewModel.swift +++ b/Sources/SmileID/Classes/SelfieCapture/SelfieViewModel.swift @@ -137,6 +137,7 @@ public class SelfieViewModel: ObservableObject, ARKitSmileDelegate { } selfieImage = nil livenessImages = [] + cleanUpSelfieCapture() } return } @@ -296,10 +297,19 @@ public class SelfieViewModel: ObservableObject, ARKitSmileDelegate { selfieImage = nil livenessImages = [] shouldAnalyzeImages = true + cleanUpSelfieCapture() localMetadata.metadata.removeAllOfType(Metadatum.SelfieImageOrigin.self) localMetadata.metadata.removeAllOfType(Metadatum.SelfieCaptureDuration.self) } + func cleanUpSelfieCapture() { + do { + try LocalStorage.deleteLivenessAndSelfieFiles(at: [jobId]) + } catch { + debugPrint(error.localizedDescription) + } + } + func onRetry() { // If selfie file is present, all captures were completed, so we're retrying a network issue if selfieImage != nil, livenessImages.count == numLivenessImages { @@ -463,7 +473,8 @@ public class SelfieViewModel: ObservableObject, ARKitSmileDelegate { if let selfieImage = selfieImage, let selfiePath = getRelativePath(from: selfieImage), livenessImages.count == numLivenessImages, - !livenessImages.contains(where: { getRelativePath(from: $0) == nil }) { + !livenessImages.contains(where: { getRelativePath(from: $0) == nil }) + { let livenessImagesPaths = livenessImages.compactMap { getRelativePath(from: $0) } callback.didSucceed( diff --git a/Sources/SmileID/Classes/SmileID.swift b/Sources/SmileID/Classes/SmileID.swift index 7e8b8850..b56618e0 100644 --- a/Sources/SmileID/Classes/SmileID.swift +++ b/Sources/SmileID/Classes/SmileID.swift @@ -6,7 +6,7 @@ import UIKit public class SmileID { /// The default value for `timeoutIntervalForRequest` for URLSession default configuration. public static let defaultRequestTimeout: TimeInterval = 60 - public static let version = "10.2.15" + public static let version = "10.2.16" @Injected var injectedApi: SmileIDServiceable public static var configuration: Config { config }