Skip to content

Commit

Permalink
feat: clear files on retry and on start capture (#251)
Browse files Browse the repository at this point in the history
* feat: clear files on retry and on start capture

* feat: clear files on retry and on start capture

* feat: rename cleanup func
  • Loading branch information
JNdhlovu authored Nov 7, 2024
1 parent dbe958d commit c61c844
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -51,7 +51,7 @@ SPEC CHECKSUMS:
lottie-ios: fcb5e73e17ba4c983140b7d21095c834b3087418
netfox: 9d5cc727fe7576c4c7688a2504618a156b7d44b7
Sentry: f8374b5415bc38dfb5645941b3ae31230fbeae57
SmileID: 0ce57af077a6d201d382b67209f9d8742db6c97b
SmileID: 3c6d3101c7da84fe9acc36c10d2a189192f00d13
SwiftLint: 3fe909719babe5537c552ee8181c0031392be933
ZIPFoundation: b8c29ea7ae353b309bc810586181fd073cb3312c

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.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' => '[email protected]', 'Juma Allan' => '[email protected]', 'Vansh Gandhi' => '[email protected]'}
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'
Expand Down
20 changes: 20 additions & 0 deletions Sources/SmileID/Classes/Helpers/LocalStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 12 additions & 1 deletion Sources/SmileID/Classes/SelfieCapture/SelfieViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public class SelfieViewModel: ObservableObject, ARKitSmileDelegate {
}
selfieImage = nil
livenessImages = []
cleanUpSelfieCapture()
}
return
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmileID/Classes/SmileID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit c61c844

Please sign in to comment.