Skip to content

Commit c61c844

Browse files
authored
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
1 parent dbe958d commit c61c844

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes
22

3+
## 10.2.16
4+
### Fixed
5+
* Clear images on retry or start capture with the same jobId
6+
37
## 10.2.15
48

59
### Changed

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ PODS:
1212
- Sentry (8.36.0):
1313
- Sentry/Core (= 8.36.0)
1414
- Sentry/Core (8.36.0)
15-
- SmileID (10.2.15):
15+
- SmileID (10.2.16):
1616
- FingerprintJS
1717
- lottie-ios (~> 4.4.2)
1818
- ZIPFoundation (~> 0.9)
@@ -51,7 +51,7 @@ SPEC CHECKSUMS:
5151
lottie-ios: fcb5e73e17ba4c983140b7d21095c834b3087418
5252
netfox: 9d5cc727fe7576c4c7688a2504618a156b7d44b7
5353
Sentry: f8374b5415bc38dfb5645941b3ae31230fbeae57
54-
SmileID: 0ce57af077a6d201d382b67209f9d8742db6c97b
54+
SmileID: 3c6d3101c7da84fe9acc36c10d2a189192f00d13
5555
SwiftLint: 3fe909719babe5537c552ee8181c0031392be933
5656
ZIPFoundation: b8c29ea7ae353b309bc810586181fd073cb3312c
5757

SmileID.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Pod::Spec.new do |s|
22
s.name = 'SmileID'
3-
s.version = '10.2.15'
3+
s.version = '10.2.16'
44
s.summary = 'The Official Smile Identity iOS SDK.'
55
s.homepage = 'https://docs.usesmileid.com/integration-options/mobile/ios-v10-beta'
66
s.license = { :type => 'MIT', :file => 'LICENSE' }
77
s.author = { 'Japhet' => 'japhet@usesmileid.com', 'Juma Allan' => 'juma@usesmileid.com', 'Vansh Gandhi' => 'vansh@usesmileid.com'}
8-
s.source = { :git => "https://github.com/smileidentity/ios.git", :tag => "v10.2.14" }
8+
s.source = { :git => "https://github.com/smileidentity/ios.git", :tag => "v10.2.16" }
99
s.ios.deployment_target = '13.0'
1010
s.dependency 'ZIPFoundation', '~> 0.9'
1111
s.dependency 'FingerprintJS'

Sources/SmileID/Classes/Helpers/LocalStorage.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,26 @@ public class LocalStorage {
356356
try fileManager.removeItem(atPath: defaultDirectory.relativePath)
357357
}
358358
}
359+
360+
static func deleteLivenessAndSelfieFiles(at jobIds: [String]) throws {
361+
func deleteMatchingFiles(in directory: URL) throws {
362+
let contents = try FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: nil)
363+
try contents.forEach { url in
364+
let filename = url.lastPathComponent
365+
if filename.starts(with: "si_liveness_") || filename.starts(with: "si_selfie_") {
366+
try delete(at: url)
367+
}
368+
}
369+
}
370+
371+
try jobIds.forEach { jobId in
372+
let unsubmittedJob = try unsubmittedJobDirectory.appendingPathComponent(jobId)
373+
try deleteMatchingFiles(in: unsubmittedJob)
374+
375+
let submittedJob = try submittedJobDirectory.appendingPathComponent(jobId)
376+
try deleteMatchingFiles(in: submittedJob)
377+
}
378+
}
359379
}
360380

361381
public extension Date {

Sources/SmileID/Classes/SelfieCapture/SelfieViewModel.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public class SelfieViewModel: ObservableObject, ARKitSmileDelegate {
137137
}
138138
selfieImage = nil
139139
livenessImages = []
140+
cleanUpSelfieCapture()
140141
}
141142
return
142143
}
@@ -296,10 +297,19 @@ public class SelfieViewModel: ObservableObject, ARKitSmileDelegate {
296297
selfieImage = nil
297298
livenessImages = []
298299
shouldAnalyzeImages = true
300+
cleanUpSelfieCapture()
299301
localMetadata.metadata.removeAllOfType(Metadatum.SelfieImageOrigin.self)
300302
localMetadata.metadata.removeAllOfType(Metadatum.SelfieCaptureDuration.self)
301303
}
302304

305+
func cleanUpSelfieCapture() {
306+
do {
307+
try LocalStorage.deleteLivenessAndSelfieFiles(at: [jobId])
308+
} catch {
309+
debugPrint(error.localizedDescription)
310+
}
311+
}
312+
303313
func onRetry() {
304314
// If selfie file is present, all captures were completed, so we're retrying a network issue
305315
if selfieImage != nil, livenessImages.count == numLivenessImages {
@@ -463,7 +473,8 @@ public class SelfieViewModel: ObservableObject, ARKitSmileDelegate {
463473
if let selfieImage = selfieImage,
464474
let selfiePath = getRelativePath(from: selfieImage),
465475
livenessImages.count == numLivenessImages,
466-
!livenessImages.contains(where: { getRelativePath(from: $0) == nil }) {
476+
!livenessImages.contains(where: { getRelativePath(from: $0) == nil })
477+
{
467478
let livenessImagesPaths = livenessImages.compactMap { getRelativePath(from: $0) }
468479

469480
callback.didSucceed(

Sources/SmileID/Classes/SmileID.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import UIKit
66
public class SmileID {
77
/// The default value for `timeoutIntervalForRequest` for URLSession default configuration.
88
public static let defaultRequestTimeout: TimeInterval = 60
9-
public static let version = "10.2.15"
9+
public static let version = "10.2.16"
1010
@Injected var injectedApi: SmileIDServiceable
1111
public static var configuration: Config { config }
1212

0 commit comments

Comments
 (0)