Skip to content

Commit

Permalink
Fix delegate (#77)
Browse files Browse the repository at this point in the history
* Fix delegate

* Bump versions

* Update Sources/SmileID/Resources/Localization/en.lproj/Localizable.strings

Co-authored-by: Michael <[email protected]>

* renamed instructions and re-ordered products

* Update Swift Docs

---------

Co-authored-by: Michael <[email protected]>
Co-authored-by: Juma Allan <[email protected]>
  • Loading branch information
3 people authored Oct 4, 2023
1 parent c1eeaad commit 97de4ee
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 74 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
## 10.0.0-beta09 (unreleased)
## 10.0.0-beta10 (unreleased)

### Added

### Changed

### Fixed

### Removed

## 10.0.0-beta09

### Fixed
- Fixed a bug where Document Verification results were not being delivered to the delegate

## 10.0.0-beta08

### Added
Expand Down
2 changes: 2 additions & 0 deletions Example/SmileID/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class HomeViewModel: ObservableObject, SmartSelfieResultDelegate, DocumentCaptur
documentBackImage: URL?,
jobStatusResponse: JobStatusResponse
) {
showToast = true
toastMessage = "Document Verification submitted successfully, results processing"
}

@objc func handleAuthCompletion(_ notification: NSNotification) {
Expand Down
8 changes: 4 additions & 4 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.0.0-beta08'
s.version = '10.0.0-beta09'
s.summary = 'The Official Smile Identity iOS SDK.'
s.homepage = "https://docs.smileidentity.com/mobile/ios"
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.homepage = 'https://docs.usesmileid.com/integration-options/mobile/ios-v10-beta'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Jubril O' => '[email protected]', 'Japhet' => '[email protected]', 'Juma Allan' => '[email protected]', 'Vansh Gandhi' => '[email protected]'}
s.source = { :git => "https://github.com/smileidentity/ios.git", :tag => "v10.0.0-beta08" }
s.source = { :git => "https://github.com/smileidentity/ios.git", :tag => "v10.0.0-beta09" }
s.ios.deployment_target = '13.0'
s.dependency 'Zip', '~> 2.1.0'
s.swift_version = '5.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DocumentCaptureViewModel: ObservableObject,
}

weak var rectangleDetectionDelegate: RectangleDetectionDelegate?
weak var captureResultDelegate: DocumentCaptureResultDelegate?
var captureResultDelegate: DocumentCaptureResultDelegate?
var router: Router<NavigationDestination>?
private var cameraCapture: Bool = false
private let textDetector = TextDetector()
Expand Down Expand Up @@ -111,7 +111,8 @@ class DocumentCaptureViewModel: ObservableObject,
selfie: Data? = nil,
captureBothSides: Bool,
showAttribution: Bool,
allowGalleryUpload: Bool
allowGalleryUpload: Bool,
delegate: DocumentCaptureResultDelegate
) {
self.userId = userId
self.jobId = jobId
Expand All @@ -122,6 +123,7 @@ class DocumentCaptureViewModel: ObservableObject,
self.captureBothSides = captureBothSides
self.showAttribution = showAttribution
self.allowGalleryUpload = allowGalleryUpload
captureResultDelegate = delegate

autoCaptureTimer = RestartableTimer(
timeInterval: autoCaptureDelayInSecs,
Expand Down Expand Up @@ -274,6 +276,8 @@ class DocumentCaptureViewModel: ObservableObject,
documentBackImage: savedFiles.documentBack,
jobStatusResponse: response
)
} else {
captureResultDelegate?.didError(error: SmileIDError.unknown("Unknown Error"))
}
default:
break
Expand All @@ -297,8 +301,7 @@ class DocumentCaptureViewModel: ObservableObject,
router?.push(
.documentBackCaptureInstructionScreen(
documentCaptureViewModel: self,
skipDestination: selfieCaptureScreen,
delegate: captureResultDelegate
skipDestination: selfieCaptureScreen
)
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ public struct DocumentCaptureInstructionsView: View {
@ObservedObject private var viewModel: DocumentCaptureViewModel
private var side: Side
private var skipDestination: NavigationDestination?
private weak var documentCaptureDelegate: DocumentCaptureResultDelegate?

init(
viewModel: DocumentCaptureViewModel,
side: Side,
skipDestination: NavigationDestination? = nil,
delegate: DocumentCaptureResultDelegate
skipDestination: NavigationDestination? = nil
) {
self.viewModel = viewModel
self.side = side
self.skipDestination = skipDestination
documentCaptureDelegate = delegate
}

fileprivate init(viewModel: DocumentCaptureViewModel) {
Expand Down Expand Up @@ -81,8 +78,7 @@ public struct DocumentCaptureInstructionsView: View {
],
captureType: .document(.back),
destination: .documentCaptureScreen(
documentCaptureViewModel: viewModel,
delegate: documentCaptureDelegate
documentCaptureViewModel: viewModel
),
secondaryDestination: .imagePicker(viewModel: viewModel),
skipDestination: skipDestination,
Expand Down Expand Up @@ -115,8 +111,7 @@ public struct DocumentCaptureInstructionsView: View {
],
captureType: .document(.front),
destination: .documentCaptureScreen(
documentCaptureViewModel: viewModel,
delegate: documentCaptureDelegate
documentCaptureViewModel: viewModel
),
secondaryDestination: .imagePicker(viewModel: viewModel),
showAttribution: viewModel.showAttribution,
Expand All @@ -135,8 +130,20 @@ struct DocumentCaptureInstructionsView_Previews: PreviewProvider {
documentType: "",
captureBothSides: true,
showAttribution: true,
allowGalleryUpload: true
allowGalleryUpload: true,
delegate: DocPlaceHolderDelegate()
)
).environment(\.locale, Locale(identifier: "en"))
}

private class DocPlaceHolderDelegate: DocumentCaptureResultDelegate {
func didSucceed(
selfie: URL,
documentFrontImage: URL,
documentBackImage: URL?,
jobStatusResponse: JobStatusResponse
) {}

func didError(error _: Error) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,20 @@ struct DocumentCaptureView_Previews: PreviewProvider {
documentType: "",
captureBothSides: true,
showAttribution: true,
allowGalleryUpload: true
allowGalleryUpload: true,
delegate: DocPlaceHolderDelegate()
)
)
}

private class DocPlaceHolderDelegate: DocumentCaptureResultDelegate {
func didSucceed(
selfie: URL,
documentFrontImage: URL,
documentBackImage: URL?,
jobStatusResponse: JobStatusResponse
) {}

func didError(error _: Error) {}
}
}
12 changes: 6 additions & 6 deletions Sources/SmileID/Classes/Navigation/NavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ struct NavigationBar: View {
let backButtonHandler: () -> Void
var body: some View {
HStack {
Button {
backButtonHandler()
} label: {
Image(uiImage: SmileIDResourcesHelper.ArrowLeft)
}.padding(.leading)
Button(
action: backButtonHandler,
label: { Image(uiImage: SmileIDResourcesHelper.ArrowLeft) }
).padding(.leading)
Spacer()
}.frame(height: 50)
}
.frame(height: 50)
.frame(maxHeight: .infinity, alignment: .top)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ indirect enum NavigationDestination: ReflectiveEquatable {
delegate: SmartSelfieResultDelegate?
)
case documentFrontCaptureInstructionScreen(
documentCaptureViewModel: DocumentCaptureViewModel,
delegate: DocumentCaptureResultDelegate?
documentCaptureViewModel: DocumentCaptureViewModel
)
case documentBackCaptureInstructionScreen(
documentCaptureViewModel: DocumentCaptureViewModel,
skipDestination: NavigationDestination,
delegate: DocumentCaptureResultDelegate?
skipDestination: NavigationDestination
)
case documentCaptureScreen(
documentCaptureViewModel: DocumentCaptureViewModel,
delegate: DocumentCaptureResultDelegate?
documentCaptureViewModel: DocumentCaptureViewModel
)
case documentCaptureProcessing
case documentCaptureError(viewModel: DocumentCaptureViewModel)
Expand Down
15 changes: 6 additions & 9 deletions Sources/SmileID/Classes/Navigation/ViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,21 @@ class ViewFactory {
viewModel: selfieCaptureViewModel,
delegate: delegate ?? SelfiePlaceHolderDelegate()
)
case let .documentFrontCaptureInstructionScreen(documentCaptureViewModel, delegate):
case let .documentFrontCaptureInstructionScreen(documentCaptureViewModel):
DocumentCaptureInstructionsView(
viewModel: documentCaptureViewModel,
side: .front,
delegate: delegate ?? DocPlaceHolderDelegate()
side: .front
)
case let .documentCaptureScreen(documentCaptureViewModel, _):
case let .documentCaptureScreen(documentCaptureViewModel):
DocumentCaptureView(viewModel: documentCaptureViewModel)
case .documentBackCaptureInstructionScreen(
documentCaptureViewModel: let viewModel,
let skipDestination,
delegate: let delegate
let skipDestination
):
DocumentCaptureInstructionsView(
viewModel: viewModel,
side: .back,
skipDestination: skipDestination,
delegate: delegate ?? DocPlaceHolderDelegate()
skipDestination: skipDestination
)
case .documentCaptureProcessing:
ModalPresenter(centered: true) {
Expand All @@ -67,7 +64,7 @@ class ViewFactory {
SuccessView(
titleKey: "Document.Complete.Header",
bodyKey: "Document.Complete.Callout",
clicked: { viewModel.handleCompletion() }
clicked: viewModel.handleCompletion
)
}
case .documentCaptureError(viewModel: let viewModel):
Expand Down
65 changes: 32 additions & 33 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.0.0-beta08"
public static let version = "10.0.0-beta09"
@Injected var injectedApi: SmileIDServiceable
public static var configuration: Config { config }

Expand Down Expand Up @@ -85,7 +85,7 @@ public class SmileID {
jobId: String = generateJobId(),
allowAgentMode: Bool = false,
showAttribution: Bool = true,
showInstruction: Bool = true,
showInstructions: Bool = true,
delegate: SmartSelfieResultDelegate
)
-> some View {
Expand All @@ -96,7 +96,28 @@ public class SmileID {
allowsAgentMode: allowAgentMode,
showAttribution: showAttribution
)
let destination: NavigationDestination = showInstruction ?
let destination: NavigationDestination = showInstructions ?
.selfieInstructionScreen(selfieCaptureViewModel: viewModel, delegate: delegate) :
.selfieCaptureScreen(selfieCaptureViewModel: viewModel, delegate: delegate)
return SmileView(initialDestination: destination).environmentObject(router)
}

public class func smartSelfieAuthenticationScreen(
userId: String,
jobId: String = generateJobId(),
allowAgentMode: Bool = false,
showAttribution: Bool = true,
showInstructions: Bool = true,
delegate: SmartSelfieResultDelegate
) -> some View {
let viewModel = SelfieCaptureViewModel(
userId: userId,
jobId: jobId,
isEnroll: false,
allowsAgentMode: allowAgentMode,
showAttribution: showAttribution
)
let destination: NavigationDestination = showInstructions ?
.selfieInstructionScreen(selfieCaptureViewModel: viewModel, delegate: delegate) :
.selfieCaptureScreen(selfieCaptureViewModel: viewModel, delegate: delegate)
return SmileView(initialDestination: destination).environmentObject(router)
Expand All @@ -114,8 +135,8 @@ public class SmileID {
/// - documentType: An optional string for the type of document to be captured
/// - idAspectRatio: An optional value for the aspect ratio of the document. If no value is,
/// supplied, image analysis is done to calculate the documents aspect ratio
/// - selfie: A jpg selfie where if provided, the user will not be prompted to capture a
/// selfie and this file will be used as the selfie image.
/// - bypassSelfieCaptureWithFile: If provided, selfie capture will be bypassed using this
/// image
/// - captureBothSides: Whether to capture both sides of the ID or not. Otherwise, only the
/// front side will be captured. If this is true, an option to skip back side will still be
/// shown
Expand All @@ -130,7 +151,7 @@ public class SmileID {
countryCode: String,
documentType: String? = nil,
idAspectRatio: Double? = nil,
selfie: Data? = nil,
bypassSelfieCaptureWithFile: URL? = nil,
captureBothSides: Bool = true,
allowGalleryUpload: Bool = false,
showInstructions: Bool = true,
Expand All @@ -143,45 +164,23 @@ public class SmileID {
countryCode: countryCode,
documentType: documentType,
idAspectRatio: idAspectRatio,
selfie: selfie,
selfie: bypassSelfieCaptureWithFile.flatMap { try? Data(contentsOf: $0) },
captureBothSides: captureBothSides,
showAttribution: showAttribution,
allowGalleryUpload: allowGalleryUpload
allowGalleryUpload: allowGalleryUpload,
delegate: delegate
)

let destination = showInstructions ?
NavigationDestination.documentFrontCaptureInstructionScreen(
documentCaptureViewModel: viewModel,
delegate: delegate
documentCaptureViewModel: viewModel
) :
NavigationDestination.documentCaptureScreen(
documentCaptureViewModel: viewModel,
delegate: delegate
documentCaptureViewModel: viewModel
)
return SmileView(initialDestination: destination).environmentObject(router)
}

public class func smartSelfieAuthenticationScreen(
userId: String,
jobId: String = generateJobId(),
allowAgentMode: Bool = false,
showAttribution: Bool = true,
showInstruction: Bool = true,
delegate: SmartSelfieResultDelegate
) -> some View {
let viewModel = SelfieCaptureViewModel(
userId: userId,
jobId: jobId,
isEnroll: false,
allowsAgentMode: allowAgentMode,
showAttribution: showAttribution
)
let destination: NavigationDestination = showInstruction ?
.selfieInstructionScreen(selfieCaptureViewModel: viewModel, delegate: delegate) :
.selfieCaptureScreen(selfieCaptureViewModel: viewModel, delegate: delegate)
return SmileView(initialDestination: destination).environmentObject(router)
}

public class func setEnvironment(useSandbox: Bool) {
SmileID.useSandbox = useSandbox
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"Instructions.ClearImage" = "Clear Image";
"Instructions.GoodLightBody" = "Make sure you are in a well-lit environment where your face is clear and visible.";
"Instructions.ClearImageBody" = "Hold your phone steady so the selfie is clear and sharp. Don’t take blurry images.";
"Instructions.ClearImageBody" = "Hold your phone steady so the image is clear and sharp. Don’t take blurry photos.";
"Instructions.GoodLight" = "Good Light";
"Instructions.RemoveObstructions" = "Remove Obstructions";
"Instructions.RemoveObstructionsBody" = "Remove anything that covers your face, such glasses, masks, hats and scarves";
Expand Down

0 comments on commit 97de4ee

Please sign in to comment.