From afc009ab9e194c79ed35ca1748e7df73f8c3da21 Mon Sep 17 00:00:00 2001 From: Jay Kim Date: Mon, 7 Nov 2022 13:50:04 -0800 Subject: [PATCH] add iOS config for in memory in-app use --- swift-sdk/Internal/DependencyContainer.swift | 12 +++++++++++- swift-sdk/Internal/InAppPersistence.swift | 14 ++++++++++++++ swift-sdk/IterableConfig.swift | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/swift-sdk/Internal/DependencyContainer.swift b/swift-sdk/Internal/DependencyContainer.swift index 8ad50deeb..08d3e862c 100644 --- a/swift-sdk/Internal/DependencyContainer.swift +++ b/swift-sdk/Internal/DependencyContainer.swift @@ -138,9 +138,19 @@ struct DependencyContainer: DependencyContainerProtocol { let notificationStateProvider: NotificationStateProviderProtocol = SystemNotificationStateProvider() let localStorage: LocalStorageProtocol = LocalStorage() let inAppDisplayer: InAppDisplayerProtocol = InAppDisplayer() - let inAppPersister: InAppPersistenceProtocol = InAppFilePersister() + let inAppPersister: InAppPersistenceProtocol let urlOpener: UrlOpenerProtocol = AppUrlOpener() let applicationStateProvider: ApplicationStateProviderProtocol = AppExtensionHelper.applicationStateProvider let notificationCenter: NotificationCenterProtocol = NotificationCenter.default let apnsTypeChecker: APNSTypeCheckerProtocol = APNSTypeChecker() + + init(_ config: IterableConfig? = nil) { + if let config = config, config.useInMemoryStorageForInApps { + FileHelper.delete(filename: "itbl_inapp", ext: "json") + + self.inAppPersister = InAppInMemoryPersister() + } else { + self.inAppPersister = InAppFilePersister() + } + } } diff --git a/swift-sdk/Internal/InAppPersistence.swift b/swift-sdk/Internal/InAppPersistence.swift index a32d04fbb..8f3286dde 100644 --- a/swift-sdk/Internal/InAppPersistence.swift +++ b/swift-sdk/Internal/InAppPersistence.swift @@ -365,6 +365,20 @@ protocol InAppPersistenceProtocol { func clear() } +class InAppInMemoryPersister: InAppPersistenceProtocol { + func getMessages() -> [IterableInAppMessage] { + [] + } + + func persist(_ messages: [IterableInAppMessage]) { + return + } + + func clear() { + return + } +} + class InAppFilePersister: InAppPersistenceProtocol { init(filename: String = "itbl_inapp", ext: String = "json") { self.filename = filename diff --git a/swift-sdk/IterableConfig.swift b/swift-sdk/IterableConfig.swift index 2debd4b0b..7cc0b9d45 100644 --- a/swift-sdk/IterableConfig.swift +++ b/swift-sdk/IterableConfig.swift @@ -120,4 +120,7 @@ public class IterableConfig: NSObject { /// We allow navigation only to urls with `https` protocol (for deep links within your app or external links). /// If you want to allow other protocols, such as, `http`, `tel` etc., please add them to the list below public var allowedProtocols: [String] = [] + + /// Set whether the SDK should store in-apps only in memory, or in file storage + public var useInMemoryStorageForInApps = false }