Skip to content

Commit 7d6d0a4

Browse files
authored
Merge branch 'master' into eudc-updates
2 parents 530fdee + 3f3b3cd commit 7d6d0a4

10 files changed

+200
-27
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 6.4.14
6+
### Added
7+
- Success and Failure handlers can now be passed to following functions:
8+
`InAppManager.remove`, `InAppManager.setRead`, `IterableAPI.setEmail` and `IterableAPI.setUserId`
9+
510
## 6.4.13
611
### Added
712
- `ITBNotificationServiceExtension` has a new optional delegate in the scenario of wanting to receive and pass along push information (e.g. Firebase)

Iterable-iOS-AppExtensions.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "Iterable-iOS-AppExtensions"
33
s.module_name = "IterableAppExtensions"
4-
s.version = "6.4.13"
4+
s.version = "6.4.14"
55
s.summary = "App Extensions for Iterable SDK"
66

77
s.description = <<-DESC

Iterable-iOS-SDK.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "Iterable-iOS-SDK"
33
s.module_name = "IterableSDK"
4-
s.version = "6.4.13"
4+
s.version = "6.4.14"
55
s.summary = "Iterable's official SDK for iOS"
66

77
s.description = <<-DESC

swift-sdk/Internal/EmptyInAppManager.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Foundation
66
import UIKit
77

88
class EmptyInAppManager: IterableInternalInAppManagerProtocol {
9+
910
func start() -> Pending<Bool, Error> {
1011
Fulfill<Bool, Error>(value: true)
1112
}
@@ -34,14 +35,24 @@ class EmptyInAppManager: IterableInternalInAppManagerProtocol {
3435

3536
func remove(message _: IterableInAppMessage) {}
3637

38+
func remove(message _: IterableInAppMessage, successHandler _: OnSuccessHandler?, failureHandler _: OnFailureHandler?) {}
39+
3740
func remove(message _: IterableInAppMessage, location _: InAppLocation) {}
3841

42+
func remove(message _: IterableInAppMessage, location _: InAppLocation, successHandler _: OnSuccessHandler?, failureHandler _: OnFailureHandler?) {}
43+
3944
func remove(message _: IterableInAppMessage, location _: InAppLocation, source _: InAppDeleteSource) {}
4045

46+
func remove(message _: IterableInAppMessage, location _: InAppLocation, source _: InAppDeleteSource, successHandler _: OnSuccessHandler?, failureHandler _: OnFailureHandler?) {}
47+
4148
func remove(message _: IterableInAppMessage, location _: InAppLocation, source _: InAppDeleteSource, inboxSessionId _: String?) {}
4249

50+
func remove(message _: IterableInAppMessage, location _: InAppLocation, source _: InAppDeleteSource, inboxSessionId _: String?, successHandler _: OnSuccessHandler?, failureHandler _: OnFailureHandler?) {}
51+
4352
func set(read _: Bool, forMessage _: IterableInAppMessage) {}
4453

54+
func set(read _: Bool, forMessage _: IterableInAppMessage, successHandler _: OnSuccessHandler?, failureHandler _: OnFailureHandler?) {}
55+
4556
func getMessage(withId _: String) -> IterableInAppMessage? {
4657
nil
4758
}

swift-sdk/Internal/InAppManager.swift

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,24 @@ protocol IterableInternalInAppManagerProtocol: IterableInAppManagerProtocol, InA
1919
/// - parameter inboxSessionId: The ID of the inbox session that the message originates from.
2020
func handleClick(clickedUrl url: URL?, forMessage message: IterableInAppMessage, location: InAppLocation, inboxSessionId: String?)
2121

22+
2223
/// - parameter message: The message to remove.
2324
/// - parameter location: The location from where this message was shown. `inbox` or `inApp`.
2425
/// - parameter source: The source of deletion `inboxSwipe` or `deleteButton`.`
2526
/// - parameter inboxSessionId: The ID of the inbox session that the message originates from.
2627
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, inboxSessionId: String?)
28+
29+
/// - parameter message: The message to remove.
30+
/// - parameter location: The location from where this message was shown. `inbox` or `inApp`.
31+
/// - parameter source: The source of deletion `inboxSwipe` or `deleteButton`.`
32+
/// - parameter inboxSessionId: The ID of the inbox session that the message originates from.
33+
/// - parameter successHandler: The callback which returns `success.
34+
/// - parameter failureHandler: The callback which returns `failure.
35+
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, inboxSessionId: String?, successHandler: OnSuccessHandler?, failureHandler: OnFailureHandler?)
2736
}
2837

2938
class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
39+
3040
init(requestHandler: RequestHandlerProtocol,
3141
deviceMetadata: DeviceMetadata,
3242
fetcher: InAppFetcherProtocol,
@@ -124,26 +134,44 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
124134
func remove(message: IterableInAppMessage, location: InAppLocation) {
125135
ITBInfo()
126136

127-
removePrivate(message: message, location: location)
137+
remove(message: message, location: location, successHandler: nil, failureHandler: nil)
138+
}
139+
140+
func remove(message: IterableInAppMessage, location: InAppLocation, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) {
141+
removePrivate(message: message, location: location, successHandler: successHandler, failureHandler: failureHandler)
128142
}
129143

130144
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource) {
131-
ITBInfo()
145+
remove(message: message, location: location, source: source, successHandler: nil, failureHandler: nil)
146+
}
147+
148+
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) {
132149

133-
removePrivate(message: message, location: location, source: source)
150+
removePrivate(message: message, location: location, source: source, successHandler: successHandler, failureHandler: failureHandler)
134151
}
135152

136-
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, inboxSessionId: String? = nil) {
153+
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, inboxSessionId: String?) {
137154
ITBInfo()
138155

139-
removePrivate(message: message, location: location, source: source, inboxSessionId: inboxSessionId)
156+
remove(message: message, location: location, source: source, inboxSessionId: inboxSessionId, successHandler: nil, failureHandler: nil)
157+
}
158+
159+
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, inboxSessionId: String? = nil, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) {
160+
removePrivate(message: message, location: location, source: source, inboxSessionId: inboxSessionId, successHandler: successHandler, failureHandler: failureHandler)
140161
}
141162

142163
func set(read: Bool, forMessage message: IterableInAppMessage) {
164+
set(read: read, forMessage: message, successHandler: nil, failureHandler: nil)
165+
}
166+
167+
func set(read: Bool, forMessage message: IterableInAppMessage, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) {
143168
updateMessage(message, read: read).onSuccess { [weak self] _ in
169+
successHandler?([:])
144170
self?.callbackQueue.async { [weak self] in
145171
self?.notificationCenter.post(name: .iterableInboxChanged, object: self, userInfo: nil)
146172
}
173+
}.onError { [weak self] _ in
174+
failureHandler?(self?.description, nil)
147175
}
148176
}
149177

@@ -185,8 +213,12 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
185213

186214
func remove(message: IterableInAppMessage) {
187215
ITBInfo()
188-
189-
removePrivate(message: message)
216+
217+
remove(message: message, successHandler: nil, failureHandler: nil)
218+
}
219+
220+
func remove(message: IterableInAppMessage, successHandler: OnSuccessHandler?, failureHandler: OnFailureHandler?) {
221+
removePrivate(message: message, location: .inApp, source: nil, successHandler: successHandler, failureHandler: failureHandler)
190222
}
191223

192224
// MARK: - Private/Internal
@@ -462,16 +494,17 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
462494
private func removePrivate(message: IterableInAppMessage,
463495
location: InAppLocation = .inApp,
464496
source: InAppDeleteSource? = nil,
465-
inboxSessionId: String? = nil) {
497+
inboxSessionId: String? = nil,
498+
successHandler: OnSuccessHandler? = nil,
499+
failureHandler: OnFailureHandler? = nil) {
466500
ITBInfo()
467-
468501
updateMessage(message, didProcessTrigger: true, consumed: true)
469502
requestHandler?.inAppConsume(message: message,
470503
location: location,
471504
source: source,
472505
inboxSessionId: inboxSessionId,
473-
onSuccess: nil,
474-
onFailure: nil)
506+
onSuccess: successHandler,
507+
onFailure: failureHandler)
475508
callbackQueue.async { [weak self] in
476509
self?.notificationCenter.post(name: .iterableInboxChanged, object: self, userInfo: nil)
477510
}

swift-sdk/Internal/InternalIterableAPI.swift

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
117117
_payloadData = data
118118
}
119119

120-
func setEmail(_ email: String?, authToken: String? = nil) {
120+
func setEmail(_ email: String?, authToken: String? = nil, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) {
121121
ITBInfo()
122122

123123
if _email == email && email != nil && authToken != nil {
@@ -133,13 +133,15 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
133133

134134
_email = email
135135
_userId = nil
136+
_successCallback = successHandler
137+
_failureCallback = failureHandler
136138

137139
storeIdentifierData()
138140

139141
onLogin(authToken)
140142
}
141143

142-
func setUserId(_ userId: String?, authToken: String? = nil) {
144+
func setUserId(_ userId: String?, authToken: String? = nil, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) {
143145
ITBInfo()
144146

145147
if _userId == userId && userId != nil && authToken != nil {
@@ -155,6 +157,8 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
155157

156158
_email = nil
157159
_userId = userId
160+
_successCallback = successHandler
161+
_failureCallback = failureHandler
158162

159163
storeIdentifierData()
160164

@@ -173,6 +177,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
173177
guard let appName = pushIntegrationName else {
174178
let errorMessage = "Not registering device token - appName must not be nil"
175179
ITBError(errorMessage)
180+
_failureCallback?(errorMessage, nil)
176181
onFailure?(errorMessage, nil)
177182
return
178183
}
@@ -187,8 +192,15 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
187192
sdkVersion: localStorage.sdkVersion)
188193
requestHandler.register(registerTokenInfo: registerTokenInfo,
189194
notificationStateProvider: notificationStateProvider,
190-
onSuccess: onSuccess,
191-
onFailure: onFailure)
195+
onSuccess: { (_ data: [AnyHashable: Any]?) in
196+
self._successCallback?(data)
197+
onSuccess?(data)
198+
},
199+
onFailure: { (_ reason: String?, _ data: Data?) in
200+
self._failureCallback?(reason, data)
201+
onFailure?(reason, data)
202+
}
203+
)
192204
}
193205

194206
@discardableResult
@@ -434,6 +446,9 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
434446
private var _email: String?
435447
private var _payloadData: [AnyHashable: Any]?
436448
private var _userId: String?
449+
private var _successCallback: OnSuccessHandler? = nil
450+
private var _failureCallback: OnFailureHandler? = nil
451+
437452

438453
/// the hex representation of this device token
439454
private var hexToken: String?
@@ -543,6 +558,8 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
543558

544559
if config.autoPushRegistration {
545560
notificationStateProvider.registerForRemoteNotifications()
561+
} else {
562+
_successCallback?([:])
546563
}
547564

548565
_ = inAppManager.scheduleSync()

swift-sdk/IterableAPI.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import UIKit
77

88
@objcMembers public final class IterableAPI: NSObject {
99
/// The current SDK version
10-
public static let sdkVersion = "6.4.13"
10+
public static let sdkVersion = "6.4.14"
1111

1212
/// The email of the logged in user that this IterableAPI is using
1313
public static var email: String? {
@@ -129,12 +129,12 @@ import UIKit
129129

130130
// MARK: - SDK
131131

132-
public static func setEmail(_ email: String?, _ authToken: String? = nil) {
133-
implementation?.setEmail(email, authToken: authToken)
132+
public static func setEmail(_ email: String?, _ authToken: String? = nil, _ successHandler: OnSuccessHandler? = nil, _ failureHandler: OnFailureHandler? = nil) {
133+
implementation?.setEmail(email, authToken: authToken, successHandler: successHandler, failureHandler: failureHandler)
134134
}
135135

136-
public static func setUserId(_ userId: String?, _ authToken: String? = nil) {
137-
implementation?.setUserId(userId, authToken: authToken)
136+
public static func setUserId(_ userId: String?, _ authToken: String? = nil, _ successHandler: OnSuccessHandler? = nil, _ failureHandler: OnFailureHandler? = nil) {
137+
implementation?.setUserId(userId, authToken: authToken, successHandler: successHandler, failureHandler: failureHandler)
138138
}
139139

140140
/// Handle a Universal Link

swift-sdk/IterableInAppManagerProtocol.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,49 @@ import Foundation
2828
/// Note that this callback is called in addition to calling `IterableCustomActionDelegate` or `IterableUrlDelegate` on the button action.
2929
@objc(showMessage:consume:callbackBlock:) func show(message: IterableInAppMessage, consume: Bool, callback: ITBURLCallback?)
3030

31+
3132
/// - parameter message: The message to remove.
3233
@objc(removeMessage:) func remove(message: IterableInAppMessage)
3334

35+
/// - parameter message: The message to remove.
36+
/// - parameter successHandler: The callback which returns `success.
37+
/// - parameter failureHandler: The callback which returns `failure.
38+
@objc(removeMessage:successHandler:failureHandler:) func remove(message: IterableInAppMessage, successHandler: OnSuccessHandler?, failureHandler: OnFailureHandler?)
39+
40+
3441
/// - parameter message: The message to remove.
3542
/// - parameter location: The location from where this message was shown. `inbox` or `inApp`.
3643
@objc(removeMessage:location:) func remove(message: IterableInAppMessage, location: InAppLocation)
3744

45+
/// - parameter message: The message to remove.
46+
/// - parameter location: The location from where this message was shown. `inbox` or `inApp`.
47+
/// - parameter successHandler: The callback which returns `success.
48+
/// - parameter failureHandler: The callback which returns `failure.
49+
@objc(removeMessage:location:successHandler:failureHandler:) func remove(message: IterableInAppMessage, location: InAppLocation, successHandler: OnSuccessHandler?, failureHandler: OnFailureHandler?)
50+
51+
3852
/// - parameter message: The message to remove.
3953
/// - parameter location: The location from where this message was shown. `inbox` or `inApp`.
4054
/// - parameter source: The source of deletion `inboxSwipe` or `deleteButton`.`
4155
@objc(removeMessage:location:source:) func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource)
4256

57+
/// - parameter message: The message to remove.
58+
/// - parameter location: The location from where this message was shown. `inbox` or `inApp`.
59+
/// - parameter source: The source of deletion `inboxSwipe` or `deleteButton`.`
60+
/// - parameter successHandler: The callback which returns `success.
61+
/// - parameter failureHandler: The callback which returns `failure.
62+
@objc(removeMessage:location:source:successHandler:failureHandler:) func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, successHandler: OnSuccessHandler?, failureHandler: OnFailureHandler?)
63+
4364
/// - parameter read: Whether this inbox message was read
4465
/// - parameter message: The inbox message
4566
@objc(setRead:forMessage:) func set(read: Bool, forMessage message: IterableInAppMessage)
4667

68+
/// - parameter read: Whether this inbox message was read
69+
/// - parameter message: The inbox message
70+
/// - parameter successHandler: The callback which returns `success.
71+
/// - parameter failureHandler: The callback which returns `failure.
72+
@objc(setRead:forMessage:successHandler:failureHandler:) func set(read: Bool, forMessage message: IterableInAppMessage, successHandler: OnSuccessHandler?, failureHandler: OnFailureHandler?)
73+
4774
/// - parameter id: The id of the message
4875
/// - returns: IterableInAppMessage with the id, if it exists.
4976
@objc(getMessageWithId:) func getMessage(withId id: String) -> IterableInAppMessage?

tests/unit-tests/InboxTests.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ class InboxTests: XCTestCase {
162162
let mockInAppFetcher = MockInAppFetcher()
163163
let config = IterableConfig()
164164
config.logDelegate = AllLogDelegate()
165-
165+
166166
let internalAPI = InternalIterableAPI.initializeForTesting(
167167
config: config,
168168
inAppFetcher: mockInAppFetcher
169169
)
170-
170+
171171
let payload = """
172172
{"inAppMessages":
173173
[
@@ -190,19 +190,27 @@ class InboxTests: XCTestCase {
190190
]
191191
}
192192
""".toJsonDict()
193-
193+
194194
mockInAppFetcher.mockInAppPayloadFromServer(internalApi: internalAPI, payload).onSuccess { _ in
195195
let messages = internalAPI.inAppManager.getInboxMessages()
196196
XCTAssertEqual(messages.count, 2)
197197

198-
internalAPI.inAppManager.remove(message: messages[0], location: .inbox, source: .inboxSwipe)
198+
let messageToRemove = messages[0]
199+
internalAPI.inAppManager.remove(
200+
message: messageToRemove,
201+
location: .inbox,
202+
source: .inboxSwipe,
203+
successHandler: { _ in },
204+
failureHandler: { _, _ in }
205+
)
206+
199207
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
200208
let newMessages = internalAPI.inAppManager.getInboxMessages()
201209
XCTAssertEqual(newMessages.count, 1)
202210
expectation1.fulfill()
203211
}
204212
}
205-
213+
206214
wait(for: [expectation1], timeout: testExpectationTimeout)
207215
}
208216

0 commit comments

Comments
 (0)