Skip to content

Commit

Permalink
Merge pull request #584 from Iterable/jay/MOB-5115-in-app-in-memory
Browse files Browse the repository at this point in the history
[MOB-5115] add iOS config for in memory in-app use
  • Loading branch information
roninopf authored Nov 8, 2022
2 parents cfa8776 + afc009a commit 9ff8fed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
12 changes: 11 additions & 1 deletion swift-sdk/Internal/DependencyContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
14 changes: 14 additions & 0 deletions swift-sdk/Internal/InAppPersistence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions swift-sdk/IterableConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 9ff8fed

Please sign in to comment.