Skip to content

Commit 9ff8fed

Browse files
authored
Merge pull request #584 from Iterable/jay/MOB-5115-in-app-in-memory
[MOB-5115] add iOS config for in memory in-app use
2 parents cfa8776 + afc009a commit 9ff8fed

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

swift-sdk/Internal/DependencyContainer.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,19 @@ struct DependencyContainer: DependencyContainerProtocol {
138138
let notificationStateProvider: NotificationStateProviderProtocol = SystemNotificationStateProvider()
139139
let localStorage: LocalStorageProtocol = LocalStorage()
140140
let inAppDisplayer: InAppDisplayerProtocol = InAppDisplayer()
141-
let inAppPersister: InAppPersistenceProtocol = InAppFilePersister()
141+
let inAppPersister: InAppPersistenceProtocol
142142
let urlOpener: UrlOpenerProtocol = AppUrlOpener()
143143
let applicationStateProvider: ApplicationStateProviderProtocol = AppExtensionHelper.applicationStateProvider
144144
let notificationCenter: NotificationCenterProtocol = NotificationCenter.default
145145
let apnsTypeChecker: APNSTypeCheckerProtocol = APNSTypeChecker()
146+
147+
init(_ config: IterableConfig? = nil) {
148+
if let config = config, config.useInMemoryStorageForInApps {
149+
FileHelper.delete(filename: "itbl_inapp", ext: "json")
150+
151+
self.inAppPersister = InAppInMemoryPersister()
152+
} else {
153+
self.inAppPersister = InAppFilePersister()
154+
}
155+
}
146156
}

swift-sdk/Internal/InAppPersistence.swift

+14
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,20 @@ protocol InAppPersistenceProtocol {
365365
func clear()
366366
}
367367

368+
class InAppInMemoryPersister: InAppPersistenceProtocol {
369+
func getMessages() -> [IterableInAppMessage] {
370+
[]
371+
}
372+
373+
func persist(_ messages: [IterableInAppMessage]) {
374+
return
375+
}
376+
377+
func clear() {
378+
return
379+
}
380+
}
381+
368382
class InAppFilePersister: InAppPersistenceProtocol {
369383
init(filename: String = "itbl_inapp", ext: String = "json") {
370384
self.filename = filename

swift-sdk/IterableConfig.swift

+3
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,7 @@ public class IterableConfig: NSObject {
120120
/// We allow navigation only to urls with `https` protocol (for deep links within your app or external links).
121121
/// If you want to allow other protocols, such as, `http`, `tel` etc., please add them to the list below
122122
public var allowedProtocols: [String] = []
123+
124+
/// Set whether the SDK should store in-apps only in memory, or in file storage
125+
public var useInMemoryStorageForInApps = false
123126
}

0 commit comments

Comments
 (0)