Skip to content

Commit

Permalink
fixup! Deprecate startEngagementWithConfig method
Browse files Browse the repository at this point in the history
This PR deprecates startEngagementWithConfig method and moves it to
deprecated methods file

MOB-2817
  • Loading branch information
rasmustautsglia committed Nov 8, 2023
1 parent dab4c0d commit 6635dff
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions TestingApp/ViewController/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -156,7 +152,7 @@ class ViewController: UIViewController {
return
}
self?.showEngagementKindActionSheet { kind in
self?.startEngagement(with: kind, config: fileName)
self?.startEngagement(with: kind)
}
}
}
Expand Down Expand Up @@ -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()
Expand All @@ -230,7 +226,7 @@ extension ViewController {
}

func configureSDK(
uiConfig: RemoteConfiguration?,
uiConfigName: String?,
completion: ((Result<Void, Error>) -> Void)? = nil
) {
let originalTitle = configureButton.title(for: .normal)
Expand All @@ -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:
Expand Down Expand Up @@ -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(
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6635dff

Please sign in to comment.