From a6824ee018f8f1c3dc23649d8c89101b6ea22731 Mon Sep 17 00:00:00 2001 From: Duncan Date: Fri, 23 Jun 2023 13:20:09 +0200 Subject: [PATCH 1/2] feat: added the ability to use previously created journey --- .../Internal/Model/Settings/JourneySettings.swift | 4 +++- .../alloy-codeless-lite-ios/Services/JourneyService.swift | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/JourneySettings.swift b/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/JourneySettings.swift index 706836c..a2cc33d 100644 --- a/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/JourneySettings.swift +++ b/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/JourneySettings.swift @@ -9,13 +9,15 @@ import Foundation public class JourneySettings { public var journeyToken: String = "" + public var journeyApplicationToken: String? public var entities: EntityData = EntityData(entities: [], additionalEntities: false) public var production: Bool = false; public var showDebugInfo: Bool = false init() {} - public init(journeyToken: String, entities: EntityData, production: Bool, showDebugInfo: Bool = false) { + public init(journeyToken: String, journeyApplicationToken: String? = nil, entities: EntityData, production: Bool, showDebugInfo: Bool = false) { self.journeyToken = journeyToken + self.journeyApplicationToken = journeyApplicationToken self.entities = entities self.production = production self.showDebugInfo = showDebugInfo diff --git a/Sources/alloy-codeless-lite-ios/Services/JourneyService.swift b/Sources/alloy-codeless-lite-ios/Services/JourneyService.swift index ac1cf56..2a4c4c7 100644 --- a/Sources/alloy-codeless-lite-ios/Services/JourneyService.swift +++ b/Sources/alloy-codeless-lite-ios/Services/JourneyService.swift @@ -15,7 +15,12 @@ internal struct JourneyService { internal mutating func startJourney(journeySettings: JourneySettings, onFinish: @escaping (FinishJourneyResult?) -> Void) async throws -> StartJourneyResult? { self.onFinish = onFinish self.journeySettings = journeySettings - let result = try await createJourney() + + if let journeyApplicationToken = journeySettings.journeyApplicationToken { + TokenHolder.tokens.journeyApplicationToken = journeyApplicationToken + } + + let result = journeySettings.journeyApplicationToken == nil ? try await createJourney() : try await getStatusJourney() if result.resultCode == .RESULT_OK, result.journeyResultData != nil { let urlPlugin = PluginURLBuilder( apiKey: AlloyCodelessLiteiOS.shared.alloySettings.apiKey ?? "", From f59985e3bddda091637737cf8fe4418cc6a1e68b Mon Sep 17 00:00:00 2001 From: Duncan Date: Fri, 23 Jun 2023 13:40:24 +0200 Subject: [PATCH 2/2] feat: changed JourneySettings init to have two options --- .../Internal/Model/Settings/JourneySettings.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/JourneySettings.swift b/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/JourneySettings.swift index a2cc33d..7d1d79a 100644 --- a/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/JourneySettings.swift +++ b/Sources/alloy-codeless-lite-ios/Internal/Model/Settings/JourneySettings.swift @@ -15,11 +15,19 @@ public class JourneySettings { public var showDebugInfo: Bool = false init() {} - public init(journeyToken: String, journeyApplicationToken: String? = nil, entities: EntityData, production: Bool, showDebugInfo: Bool = false) { + public init(journeyToken: String, entities: EntityData, production: Bool, showDebugInfo: Bool = false) { self.journeyToken = journeyToken - self.journeyApplicationToken = journeyApplicationToken + self.journeyApplicationToken = nil self.entities = entities self.production = production self.showDebugInfo = showDebugInfo } + + public init(journeyToken: String, journeyApplicationToken: String? = nil, production: Bool, showDebugInfo: Bool = false) { + self.journeyToken = journeyToken + self.journeyApplicationToken = journeyApplicationToken + self.entities = EntityData(entities: [], additionalEntities: false) + self.production = production + self.showDebugInfo = showDebugInfo + } }