From 6635dff0da5f70617c12c3728984e9787a329d15 Mon Sep 17 00:00:00 2001 From: Rasmus Tauts Date: Wed, 8 Nov 2023 13:51:57 +0200 Subject: [PATCH] fixup! Deprecate startEngagementWithConfig method This PR deprecates startEngagementWithConfig method and moves it to deprecated methods file MOB-2817 --- .../ViewController/ViewController.swift | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/TestingApp/ViewController/ViewController.swift b/TestingApp/ViewController/ViewController.swift index da0adac0b..b5e385604 100644 --- a/TestingApp/ViewController/ViewController.swift +++ b/TestingApp/ViewController/ViewController.swift @@ -121,11 +121,7 @@ class ViewController: UIViewController { @IBAction private func configureSDKTapped() { showRemoteConfigAlert { [weak self] fileName in - var config: RemoteConfiguration? - if let fileName = fileName { - config = self?.retrieveRemoteConfiguration(fileName) - } - self?.configureSDK(uiConfig: config) { [weak self] result in + self?.configureSDK(uiConfigName: fileName) { [weak self] result in guard case let .failure(error) = result else { return } self?.showErrorAlert(using: error) } @@ -137,7 +133,7 @@ class ViewController: UIViewController { // only if such engagement exists, we need // to configure SDK, and only then attempt // to end engagement. - configureSDK(uiConfig: nil) { [weak self] result in + configureSDK(uiConfigName: nil) { [weak self] result in switch result { case .success: Glia.sharedInstance.endEngagement { result in @@ -156,7 +152,7 @@ class ViewController: UIViewController { return } self?.showEngagementKindActionSheet { kind in - self?.startEngagement(with: kind, config: fileName) + self?.startEngagement(with: kind) } } } @@ -216,7 +212,7 @@ extension ViewController { } if autoConfigureSdkToggle.isOn { - configureSDK(uiConfig: nil) { [weak self] result in + configureSDK(uiConfigName: nil) { [weak self] result in switch result { case .success: startEngagement() @@ -230,7 +226,7 @@ extension ViewController { } func configureSDK( - uiConfig: RemoteConfiguration?, + uiConfigName: String?, completion: ((Result) -> Void)? = nil ) { let originalTitle = configureButton.title(for: .normal) @@ -244,9 +240,12 @@ extension ViewController { debugPrint(printable) } + let uiConfig = retrieveRemoteConfiguration(uiConfigName) + do { try Glia.sharedInstance.configure( - with: configuration + with: configuration, + uiConfig: uiConfig ) { result in switch result { case .success: @@ -303,9 +302,7 @@ extension ViewController { present(alert, animated: true) } - private func startEngagement(with kind: EngagementKind, config name: String) { - guard let config = retrieveRemoteConfiguration(name) else { return } - + private func startEngagement(with kind: EngagementKind) { let startEngagement = { self.catchingError { try Glia.sharedInstance.startEngagement( @@ -316,7 +313,7 @@ extension ViewController { } if autoConfigureSdkToggle.isOn { - configureSDK(uiConfig: nil) { [weak self] result in + configureSDK(uiConfigName: nil) { [weak self] result in switch result { case .success: startEngagement() @@ -363,13 +360,13 @@ extension ViewController { present(alert, animated: true) } - func retrieveRemoteConfiguration(_ fileName: String) -> RemoteConfiguration? { + func retrieveRemoteConfiguration(_ fileName: String?) -> RemoteConfiguration? { guard let url = Bundle.main.url(forResource: fileName, withExtension: "json", subdirectory: "UnifiedUI"), let jsonData = try? Data(contentsOf: url), let config = try? JSONDecoder().decode(RemoteConfiguration.self, from: .init(jsonData)) else { - alert(message: "Could not decode RemoteConfiguration.") + print("Could not decode RemoteConfiguration.") return nil } return config