Skip to content

Commit 275f4cf

Browse files
author
“Akshay
committed
No Offline Components when Online-Only
1. Turned the default value to false instead of true. Only once the response comes back as true, the value will be set to true. Subsequent launches will respect whats stored after that. There will not be a toggling happening every now and then. Once the response from server is received as true, its stored in the sdk. 2. Create RequestHandler initializes both online and offline request Handler irrespective of the feature enabled or disabled. Added lazy var for offlineprocessor and initializing offline componenents only when offlineMode is true. This change will make sure that components like TaskSchedular and HealthMonitor will not be even initialized unless offlineMode is true. However, this change does not engage offlineMode immediately after the response is received as true as creation of request handler has already passed and only a fresh launch of app can then go through offline request processor. Additional changes are needed to make sure offlineMode when accessed, initializes its component and not when requestHandler is initialized. That will keep the offline component encapsulated within offline flow.
1 parent 26359d3 commit 275f4cf

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

swift-sdk/Internal/DependencyContainerProtocol.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,31 @@ extension DependencyContainerProtocol {
7070
networkSession: networkSession,
7171
deviceMetadata: deviceMetadata,
7272
dateProvider: dateProvider)
73-
if let persistenceContextProvider = createPersistenceContextProvider() {
74-
let healthMonitorDataProvider = createHealthMonitorDataProvider(persistenceContextProvider: persistenceContextProvider)
75-
let healthMonitor = HealthMonitor(dataProvider: healthMonitorDataProvider,
73+
lazy var offlineProcessor:OfflineRequestProcessor? = nil
74+
lazy var healthMonitor: HealthMonitor? = nil
75+
76+
77+
if(offlineMode) {
78+
if let persistenceContextProvider = createPersistenceContextProvider() {
79+
80+
let healthMonitorDataProvider = createHealthMonitorDataProvider(persistenceContextProvider: persistenceContextProvider)
81+
82+
healthMonitor = HealthMonitor(dataProvider: healthMonitorDataProvider,
7683
dateProvider: dateProvider,
7784
networkSession: networkSession)
78-
let offlineProcessor = OfflineRequestProcessor(apiKey: apiKey,
85+
offlineProcessor = OfflineRequestProcessor(apiKey: apiKey,
7986
authProvider: authProvider,
8087
authManager: authManager,
8188
endpoint: endpoint,
8289
deviceMetadata: deviceMetadata,
8390
taskScheduler: createTaskScheduler(persistenceContextProvider: persistenceContextProvider,
84-
healthMonitor: healthMonitor),
91+
healthMonitor: healthMonitor!),
8592
taskRunner: createTaskRunner(persistenceContextProvider: persistenceContextProvider,
86-
healthMonitor: healthMonitor),
93+
healthMonitor: healthMonitor!),
8794
notificationCenter: notificationCenter)
88-
return RequestHandler(onlineProcessor: onlineProcessor,
95+
}
96+
97+
return RequestHandler(onlineProcessor: onlineProcessor,
8998
offlineProcessor: offlineProcessor,
9099
healthMonitor: healthMonitor,
91100
offlineMode: offlineMode)

swift-sdk/Internal/RequestHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class RequestHandler: RequestHandlerProtocol {
88
init(onlineProcessor: OnlineRequestProcessor,
99
offlineProcessor: OfflineRequestProcessor?,
1010
healthMonitor: HealthMonitor?,
11-
offlineMode: Bool = true) {
11+
offlineMode: Bool = false) {
1212
ITBInfo()
1313
self.onlineProcessor = onlineProcessor
1414
self.offlineProcessor = offlineProcessor

0 commit comments

Comments
 (0)