@@ -23,10 +23,13 @@ protocol IterableInternalInAppManagerProtocol: IterableInAppManagerProtocol, InA
23
23
/// - parameter location: The location from where this message was shown. `inbox` or `inApp`.
24
24
/// - parameter source: The source of deletion `inboxSwipe` or `deleteButton`.`
25
25
/// - parameter inboxSessionId: The ID of the inbox session that the message originates from.
26
- func remove( message: IterableInAppMessage , location: InAppLocation , source: InAppDeleteSource , inboxSessionId: String ? )
26
+ /// - parameter successHandler: The callback which returns `success.
27
+ /// - parameter failureHandler: The callback which returns `failure.
28
+ func remove( message: IterableInAppMessage , location: InAppLocation , source: InAppDeleteSource , inboxSessionId: String ? , successHandler: OnSuccessHandler ? , failureHandler: OnFailureHandler ? )
27
29
}
28
30
29
31
class InAppManager : NSObject , IterableInternalInAppManagerProtocol {
32
+
30
33
init ( requestHandler: RequestHandlerProtocol ,
31
34
deviceMetadata: DeviceMetadata ,
32
35
fetcher: InAppFetcherProtocol ,
@@ -121,33 +124,31 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
121
124
}
122
125
}
123
126
124
- func remove( message: IterableInAppMessage , location: InAppLocation , onCompletion : OnCompletionHandler ? ) {
127
+ func remove( message: IterableInAppMessage , location: InAppLocation , successHandler : OnSuccessHandler ? = nil , failureHandler : OnFailureHandler ? = nil ) {
125
128
ITBInfo ( )
126
- self . completionHandler = onCompletion
127
- removePrivate ( message: message, location: location)
129
+ removePrivate ( message: message, location: location, successHandler: successHandler, failureHandler: failureHandler)
128
130
}
129
131
130
- func remove( message: IterableInAppMessage , location: InAppLocation , source: InAppDeleteSource , onCompletion : OnCompletionHandler ? ) {
132
+ func remove( message: IterableInAppMessage , location: InAppLocation , source: InAppDeleteSource , successHandler : OnSuccessHandler ? = nil , failureHandler : OnFailureHandler ? = nil ) {
131
133
ITBInfo ( )
132
- self . completionHandler = onCompletion
133
- removePrivate ( message: message, location: location, source: source)
134
+ removePrivate ( message: message, location: location, source: source, successHandler: successHandler, failureHandler: failureHandler)
134
135
}
135
136
136
- func remove( message: IterableInAppMessage , location: InAppLocation , source: InAppDeleteSource , inboxSessionId: String ? = nil ) {
137
+ func remove( message: IterableInAppMessage , location: InAppLocation , source: InAppDeleteSource , inboxSessionId: String ? = nil , successHandler : OnSuccessHandler ? = nil , failureHandler : OnFailureHandler ? = nil ) {
137
138
ITBInfo ( )
138
139
139
- removePrivate ( message: message, location: location, source: source, inboxSessionId: inboxSessionId)
140
+ removePrivate ( message: message, location: location, source: source, inboxSessionId: inboxSessionId, successHandler : successHandler , failureHandler : failureHandler )
140
141
}
141
142
142
- func set( read: Bool , forMessage message: IterableInAppMessage , onCompletion: OnCompletionHandler ? ) {
143
- self . completionHandler = onCompletion
143
+ func set( read: Bool , forMessage message: IterableInAppMessage , successHandler: OnSuccessHandler ? = nil , failureHandler: OnFailureHandler ? = nil ) {
144
144
updateMessage ( message, read: read) . onSuccess { [ weak self] _ in
145
- self ? . completionHandler ? ( true )
145
+ var successObject : [ AnyHashable : Any ] = [ : ]
146
+ successHandler ? ( successObject)
146
147
self ? . callbackQueue. async { [ weak self] in
147
148
self ? . notificationCenter. post ( name: . iterableInboxChanged, object: self , userInfo: nil )
148
149
}
149
150
} . onError { [ weak self] _ in
150
- self ? . completionHandler ? ( false )
151
+ failureHandler ? ( self ? . description , nil )
151
152
}
152
153
}
153
154
@@ -187,10 +188,10 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
187
188
}
188
189
}
189
190
190
- func remove( message: IterableInAppMessage , onCompletion : OnCompletionHandler ? ) {
191
+ func remove( message: IterableInAppMessage , successHandler : OnSuccessHandler ? , failureHandler : OnFailureHandler ? ) {
191
192
ITBInfo ( )
192
193
193
- removePrivate ( message: message)
194
+ removePrivate ( message: message, location : . inApp , source : nil , successHandler : successHandler , failureHandler : failureHandler )
194
195
}
195
196
196
197
// MARK: - Private/Internal
@@ -466,20 +467,17 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
466
467
private func removePrivate( message: IterableInAppMessage ,
467
468
location: InAppLocation = . inApp,
468
469
source: InAppDeleteSource ? = nil ,
469
- inboxSessionId: String ? = nil ) {
470
+ inboxSessionId: String ? = nil ,
471
+ successHandler: OnSuccessHandler ? = nil ,
472
+ failureHandler: OnFailureHandler ? = nil ) {
470
473
ITBInfo ( )
471
-
472
474
updateMessage ( message, didProcessTrigger: true , consumed: true )
473
475
requestHandler? . inAppConsume ( message: message,
474
476
location: location,
475
477
source: source,
476
478
inboxSessionId: inboxSessionId,
477
- onSuccess: { ( _ data: [ AnyHashable : Any ] ? ) in
478
- self . completionHandler ? ( true )
479
- } ,
480
- onFailure: { ( _ reason: String ? , _ data: Data ? ) in
481
- self . completionHandler ? ( false )
482
- } )
479
+ onSuccess: successHandler,
480
+ onFailure: failureHandler)
483
481
callbackQueue. async { [ weak self] in
484
482
self ? . notificationCenter. post ( name: . iterableInboxChanged, object: self , userInfo: nil )
485
483
}
@@ -541,7 +539,6 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
541
539
private var lastSyncTime : Date ?
542
540
private var moveToForegroundSyncInterval : Double = 1.0 * 60.0 // don't sync within sixty seconds
543
541
private var autoDisplayPaused = false
544
- private var completionHandler : OnCompletionHandler ? = nil
545
542
}
546
543
547
544
extension InAppManager : InAppNotifiable {
0 commit comments