@@ -81,16 +81,20 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
81
81
notificationCenter. removeObserver ( self )
82
82
}
83
83
84
- func start( ) -> Future < Bool , Error > {
85
- ITBInfo ( )
84
+ // MARK: - IterableInAppManagerProtocol
85
+
86
+ var isAutoDisplayPaused : Bool {
87
+ get {
88
+ autoDisplayPaused
89
+ }
86
90
87
- if messagesMap. values. filter ( { $0. saveToInbox == true } ) . count > 0 {
88
- callbackQueue. async {
89
- self . notificationCenter. post ( name: . iterableInboxChanged, object: self , userInfo: nil )
91
+ set {
92
+ autoDisplayPaused = newValue
93
+
94
+ if !autoDisplayPaused {
95
+ _ = scheduleSync ( )
90
96
}
91
97
}
92
-
93
- return scheduleSync ( )
94
98
}
95
99
96
100
func getMessages( ) -> [ IterableInAppMessage ] {
@@ -109,32 +113,6 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
109
113
return getInboxMessages ( ) . filter { $0. read == false } . count
110
114
}
111
115
112
- func createInboxMessageViewController( for message: IterableInAppMessage , withInboxMode inboxMode: IterableInboxViewController . InboxMode , inboxSessionId: String ? = nil ) -> UIViewController ? {
113
- guard let content = message. content as? IterableHtmlInAppContent else {
114
- ITBError ( " Invalid Content in message " )
115
- return nil
116
- }
117
-
118
- let parameters = IterableHtmlMessageViewController . Parameters ( html: content. html,
119
- padding: content. edgeInsets,
120
- messageMetadata: IterableInAppMessageMetadata ( message: message, location: . inbox) ,
121
- isModal: inboxMode == . popup,
122
- inboxSessionId: inboxSessionId)
123
- let createResult = IterableHtmlMessageViewController . create ( parameters: parameters)
124
- let viewController = createResult. viewController
125
-
126
- createResult. futureClickedURL. onSuccess { url in
127
- ITBInfo ( )
128
-
129
- // in addition perform action or url delegate task
130
- self . handle ( clickedUrl: url, forMessage: message, location: . inbox)
131
- }
132
-
133
- viewController. navigationItem. title = message. inboxMetadata? . title
134
-
135
- return viewController
136
- }
137
-
138
116
func show( message: IterableInAppMessage ) {
139
117
ITBInfo ( )
140
118
@@ -150,12 +128,6 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
150
128
}
151
129
}
152
130
153
- func remove( message: IterableInAppMessage ) {
154
- ITBInfo ( )
155
-
156
- removePrivate ( message: message)
157
- }
158
-
159
131
func remove( message: IterableInAppMessage , location: InAppLocation ) {
160
132
ITBInfo ( )
161
133
@@ -186,25 +158,56 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
186
158
return messagesMap [ id]
187
159
}
188
160
189
- func isOkToShowNow( message: IterableInAppMessage ) -> Bool {
190
- guard message. didProcessTrigger == false else {
191
- ITBInfo ( " message with id: \( message. messageId) is already processed " )
192
- return false
161
+ // MARK: - IterableInternalInAppManagerProtocol
162
+
163
+ func start( ) -> Future < Bool , Error > {
164
+ ITBInfo ( )
165
+
166
+ if messagesMap. values. filter ( { $0. saveToInbox } ) . count > 0 {
167
+ callbackQueue. async {
168
+ self . notificationCenter. post ( name: . iterableInboxChanged, object: self , userInfo: nil )
169
+ }
193
170
}
194
171
195
- guard InAppManager . getWaitTimeInterval ( fromLastTime: lastDismissedTime, currentTime: dateProvider. currentDate, gap: retryInterval) <= 0 else {
196
- ITBInfo ( " can't display within retryInterval window " )
197
- return false
172
+ return scheduleSync ( )
173
+ }
174
+
175
+ func createInboxMessageViewController( for message: IterableInAppMessage ,
176
+ withInboxMode inboxMode: IterableInboxViewController . InboxMode ,
177
+ inboxSessionId: String ? = nil ) -> UIViewController ? {
178
+ guard let content = message. content as? IterableHtmlInAppContent else {
179
+ ITBError ( " Invalid Content in message " )
180
+ return nil
198
181
}
199
182
200
- guard InAppManager . getWaitTimeInterval ( fromLastTime: lastDisplayTime, currentTime: dateProvider. currentDate, gap: retryInterval) <= 0 else {
201
- ITBInfo ( " can't display within retryInterval window " )
202
- return false
183
+ let parameters = IterableHtmlMessageViewController . Parameters ( html: content. html,
184
+ padding: content. edgeInsets,
185
+ messageMetadata: IterableInAppMessageMetadata ( message: message, location: . inbox) ,
186
+ isModal: inboxMode == . popup,
187
+ inboxSessionId: inboxSessionId)
188
+ let createResult = IterableHtmlMessageViewController . create ( parameters: parameters)
189
+ let viewController = createResult. viewController
190
+
191
+ createResult. futureClickedURL. onSuccess { url in
192
+ ITBInfo ( )
193
+
194
+ // in addition perform action or url delegate task
195
+ self . handle ( clickedUrl: url, forMessage: message, location: . inbox)
203
196
}
204
197
205
- return true
198
+ viewController. navigationItem. title = message. inboxMetadata? . title
199
+
200
+ return viewController
206
201
}
207
202
203
+ func remove( message: IterableInAppMessage ) {
204
+ ITBInfo ( )
205
+
206
+ removePrivate ( message: message)
207
+ }
208
+
209
+ // MARK: - Private/Internal
210
+
208
211
@objc private func onAppEnteredForeground( notification _: Notification ) {
209
212
ITBInfo ( )
210
213
@@ -301,14 +304,15 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
301
304
case let . notShown( reason) :
302
305
ITBError ( " Could not show message: \( reason) " )
303
306
case let . shown( futureClickedURL) :
304
- // set read
305
307
ITBDebug ( " in-app shown " )
308
+
306
309
set ( read: true , forMessage: message)
307
310
308
311
updateMessage ( message, didProcessTrigger: true , consumed: consume)
309
312
310
313
futureClickedURL. onSuccess { url in
311
314
ITBDebug ( " in-app clicked " )
315
+
312
316
// call the client callback, if present
313
317
_ = callback ? ( url)
314
318
@@ -350,10 +354,11 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
350
354
}
351
355
}
352
356
353
- @discardableResult private func updateMessage( _ message: IterableInAppMessage ,
354
- read: Bool ? = nil ,
355
- didProcessTrigger: Bool ? = nil ,
356
- consumed: Bool ? = nil ) -> Future < Bool , IterableError > {
357
+ @discardableResult
358
+ private func updateMessage( _ message: IterableInAppMessage ,
359
+ read: Bool ? = nil ,
360
+ didProcessTrigger: Bool ? = nil ,
361
+ consumed: Bool ? = nil ) -> Future < Bool , IterableError > {
357
362
ITBDebug ( )
358
363
359
364
let result = Promise < Bool , IterableError > ( )
@@ -478,7 +483,10 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
478
483
}
479
484
480
485
// From client side
481
- private func removePrivate( message: IterableInAppMessage , location: InAppLocation = . inApp, source: InAppDeleteSource ? = nil , inboxSessionId: String ? = nil ) {
486
+ private func removePrivate( message: IterableInAppMessage ,
487
+ location: InAppLocation = . inApp,
488
+ source: InAppDeleteSource ? = nil ,
489
+ inboxSessionId: String ? = nil ) {
482
490
ITBInfo ( )
483
491
484
492
updateMessage ( message, didProcessTrigger: true , consumed: true )
@@ -545,6 +553,7 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
545
553
private var syncResult : Future < Bool , Error > ?
546
554
private var lastSyncTime : Date ?
547
555
private let moveToForegroundSyncInterval : Double = 1.0 * 60.0 // don't sync within sixty seconds
556
+ private var autoDisplayPaused = false
548
557
}
549
558
550
559
extension InAppManager : InAppNotifiable {
@@ -613,3 +622,29 @@ extension InAppManager: InAppNotifiable {
613
622
return result
614
623
}
615
624
}
625
+
626
+ extension InAppManager : InAppDisplayChecker {
627
+ func isOkToShowNow( message: IterableInAppMessage ) -> Bool {
628
+ guard !isAutoDisplayPaused else {
629
+ ITBInfo ( " automatic in-app display has been paused " )
630
+ return false
631
+ }
632
+
633
+ guard !message. didProcessTrigger else {
634
+ ITBInfo ( " message with id: \( message. messageId) is already processed " )
635
+ return false
636
+ }
637
+
638
+ guard InAppManager . getWaitTimeInterval ( fromLastTime: lastDismissedTime, currentTime: dateProvider. currentDate, gap: retryInterval) <= 0 else {
639
+ ITBInfo ( " can't display within retryInterval window " )
640
+ return false
641
+ }
642
+
643
+ guard InAppManager . getWaitTimeInterval ( fromLastTime: lastDisplayTime, currentTime: dateProvider. currentDate, gap: retryInterval) <= 0 else {
644
+ ITBInfo ( " can't display within retryInterval window " )
645
+ return false
646
+ }
647
+
648
+ return true
649
+ }
650
+ }
0 commit comments