diff --git a/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift index a2c7241..29fbf53 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift @@ -26,7 +26,7 @@ open class ActionRestartHandler: MVMCoreActionHandlerProtocol { continuation.resume(throwing: MVMCoreError.errorObject(error)) } else { // Restarts the app (forcing any passed in page types). - MVMCoreSessionObject.sharedGlobal()?.restartSession(withPageType: model.pageType, requestUrl: model.requestURL, parameters: model.extraParameters?.toJSON(), clearAllVariables: true) + MVMCoreSessionObject.sharedGlobal()?.restartSession(withPageType: model.pageType, request: model.requestURL, parameters: model.extraParameters?.toJSON(), clearAllVariables: true) continuation.resume() } }) diff --git a/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift b/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift index c9fa9b6..30888f9 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift @@ -6,6 +6,7 @@ // Copyright © 2020 myverizon. All rights reserved. // +import Foundation public struct ActionRestartModel: ActionModelProtocol { //-------------------------------------------------- @@ -14,7 +15,7 @@ public struct ActionRestartModel: ActionModelProtocol { public static var identifier: String = "restart" public var actionType: String = ActionRestartModel.identifier - public var requestURL: String? + public var requestURL: URL? public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? @@ -25,10 +26,41 @@ public struct ActionRestartModel: ActionModelProtocol { // MARK: - Initializer //-------------------------------------------------- - public init(_ pageType: String? = nil, _ requestUrl: String? = nil, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { + public init(_ pageType: String? = nil, _ requestUrl: URL? = nil, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { self.pageType = pageType self.requestURL = requestUrl self.extraParameters = extraParameters self.analyticsData = analyticsData } + + //-------------------------------------------------- + // MARK: - Codable + //-------------------------------------------------- + private enum CodingKeys: String, CodingKey { + case actionType + case requestURL + case extraParameters + case analyticsData + case pageType + } + + public init(from decoder: Decoder) throws { + + let container = try decoder.container(keyedBy: CodingKeys.self) + self.actionType = try container.decode(String.self, forKey: .actionType) + self.requestURL = try container.decodeIfPresent(URL.self, forKey: .requestURL) + self.extraParameters = try container.decodeIfPresent(JSONValueDictionary.self, forKey: .extraParameters) + self.analyticsData = try container.decodeIfPresent(JSONValueDictionary.self, forKey: .analyticsData) + self.pageType = try container.decodeIfPresent(String.self, forKey: .pageType) + } + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(actionType, forKey: .actionType) + try container.encodeIfPresent(requestURL, forKey: .requestURL) + try container.encodeIfPresent(extraParameters, forKey: .extraParameters) + try container.encodeIfPresent(analyticsData, forKey: .analyticsData) + try container.encode(pageType, forKey: .pageType) + } } diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionObject.h b/MVMCore/MVMCore/Session/MVMCoreSessionObject.h index e82fa04..2f676b0 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionObject.h +++ b/MVMCore/MVMCore/Session/MVMCoreSessionObject.h @@ -36,7 +36,7 @@ - (nullable NSDictionary *)getInitialParametersExcludingSections:(nullable NSSet *)excludeSections; /// Restarts the application session state. Can clear variables and pass a page type if needed. -- (void)restartSessionWithPageType:(nullable NSString *)pageType requestUrl:(nullable NSString *)requestUrl parameters:(nullable NSDictionary *)parameters clearAllVariables:(BOOL)clearAllVariables; +- (void)restartSessionWithPageType:(nullable NSString *)pageType requestUrl:(nullable NSURL *)requestUrl parameters:(nullable NSDictionary *)parameters clearAllVariables:(BOOL)clearAllVariables; /// Redirect, leaving the current app experience. - (void)redirectWithInfo:(nullable NSDictionary *)dictionary; diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m index c52913d..e5bed5e 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m @@ -36,7 +36,7 @@ return nil; } -- (void)restartSessionWithPageType:(nullable NSString *)pageType requestUrl:(nullable NSString*)requestUrl parameters:(nullable NSDictionary *)parameters clearAllVariables:(BOOL)clearAllVariables { +- (void)restartSessionWithPageType:(nullable NSString *)pageType requestUrl:(nullable NSURL *)requestUrl parameters:(nullable NSDictionary *)parameters clearAllVariables:(BOOL)clearAllVariables { // Clears the singletons of any session related data. if (clearAllVariables) { [self clearSessionObject];