Skip to content

Commit

Permalink
removed scl button option
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeradkani committed Mar 4, 2024
1 parent c252cbf commit 62cce8f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 89 deletions.
12 changes: 3 additions & 9 deletions SmartCaptureDemo/Extension/WebView+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@ extension WKWebView {
return onError(.invalidFilePath)
}

do {
switch version {
case .scl:
guard let url = URL(string: ApiEndpoint.sclWebView.path) else { return }
load(URLRequest(url: url))
case .cdn:
let htmlString = try String(contentsOfFile: filePath, encoding: .utf8)
loadHTMLString(htmlString, baseURL: URL(fileURLWithPath: filePath))
}
do {
let htmlString = try String(contentsOfFile: filePath, encoding: .utf8)
loadHTMLString(htmlString, baseURL: URL(fileURLWithPath: filePath))
} catch let error {
onError(.contentConversion(error.localizedDescription))
}
Expand Down
58 changes: 2 additions & 56 deletions SmartCaptureDemo/MainVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,18 @@ import UIKit

class MainVC: UIViewController {

// MARK: - Properties

private let sclButton: UIButton = {
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("via Smart Capture Link", for: .normal)
button.setTitleColor(.white, for: .normal)
button.backgroundColor = UIColor(named: "primaryDarkColor")
button.layer.cornerRadius = 8
button.addTarget(self, action: #selector(sclPressed), for: .primaryActionTriggered)
return button
}()

private let cdnButton: UIButton = {
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("via Content Delivery Network", for: .normal)
button.setTitleColor(.white, for: .normal)
button.backgroundColor = UIColor(named: "primaryLightColor")
button.layer.cornerRadius = 8
button.addTarget(self, action: #selector(cdnPressed), for: .primaryActionTriggered)
return button
}()

// MARK: - Lifecycle

override func viewDidLoad() {
super.viewDidLoad()
setupUI()
addSubViews()
configureConstraints()
loadWebView()
}

// MARK: - Private Methods

private func setupUI() {
view.backgroundColor = .white
navigationItem.title = "Web SDK Demo"
}

private func addSubViews() {
view.addSubview(sclButton)
view.addSubview(cdnButton)
}

private func configureConstraints() {
NSLayoutConstraint.activate([
sclButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
sclButton.centerYAnchor.constraint(equalTo: view.centerYAnchor),
sclButton.widthAnchor.constraint(equalToConstant: 260),
sclButton.heightAnchor.constraint(equalToConstant: 52),
cdnButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),

cdnButton.topAnchor.constraint(equalToSystemSpacingBelow: sclButton.bottomAnchor, multiplier: 2),
cdnButton.widthAnchor.constraint(equalToConstant: 260),
cdnButton.heightAnchor.constraint(equalToConstant: 52),
])
}

// MARK: - Actions

@objc func sclPressed() {
navigationController?.pushViewController(WebViewViewController(webSDKVersion: .scl), animated: true)
}

@objc func cdnPressed() {
@objc func loadWebView() {
navigationController?.pushViewController(WebViewViewController(webSDKVersion: .cdn), animated: true)
}
}
Expand Down
36 changes: 12 additions & 24 deletions SmartCaptureDemo/WebViewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,15 @@ final class WebViewViewController: UIViewController {
var scriptSource: String?

guard let token, let workflowRunId else { return WKWebViewConfiguration() }
switch webSDKVersion {
case .scl:
scriptPath = Bundle.main.path(forResource: "webview_script", ofType: "js")
scriptSource = try? String(contentsOfFile: scriptPath ?? "")
case .cdn:
scriptSource = """
Onfido.init({
token: '\(token)',
workflowRunId: '\(workflowRunId)',
containerId: 'onfido-mount'
})
"""
}


scriptSource = """
Onfido.init({
token: '\(token)',
workflowRunId: '\(workflowRunId)',
containerId: 'onfido-mount'
})
"""

/// Inject script into WebView controller
guard let scriptSource else { return WKWebViewConfiguration() }
let contentController = WKUserContentController()
Expand Down Expand Up @@ -102,17 +97,10 @@ final class WebViewViewController: UIViewController {
webView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -12)
])

switch webSDKVersion {
case .scl:
webView.load(nil, version: .scl) { err in
print("🚨: \(err)")
}
case .cdn:
webView.load("index", version: .cdn) { err in
print("🚨🚨🚨: \(err)")
}
webView.load("index", version: .cdn) { err in
print("🚨🚨🚨: \(err)")
}

self.webView = webView
}
}
Expand Down

0 comments on commit 62cce8f

Please sign in to comment.