Skip to content

Commit 97f22b0

Browse files
committed
update code
1 parent 7cc3d7b commit 97f22b0

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

swift-sdk/Constants.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ public enum IterableCustomActionName: String, CaseIterable {
381381

382382
public typealias ITEActionBlock = (String?) -> Void
383383
public typealias ITBURLCallback = (URL?) -> Void
384+
public typealias OnCompletionHandler = (Bool) -> Void
384385
public typealias OnSuccessHandler = (_ data: [AnyHashable: Any]?) -> Void
385386
public typealias OnFailureHandler = (_ reason: String?, _ data: Data?) -> Void
386387
public typealias UrlHandler = (URL) -> Bool

swift-sdk/Internal/InternalIterableAPI.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
110110
_payloadData = data
111111
}
112112

113-
func setEmail(_ email: String?, authToken: String? = nil, resultCallback: ((Bool) -> Void)? = nil) {
113+
func setEmail(_ email: String?, authToken: String? = nil, onCompletion: OnCompletionHandler? = nil) {
114114
ITBInfo()
115115

116116
if _email == email && email != nil && authToken != nil {
@@ -126,14 +126,14 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
126126

127127
_email = email
128128
_userId = nil
129-
self.resultCallback = resultCallback
129+
_resultCallback = onCompletion
130130

131131
storeIdentifierData()
132132

133133
onLogin(authToken)
134134
}
135135

136-
func setUserId(_ userId: String?, authToken: String? = nil, resultCallback: ((Bool) -> Void)? = nil) {
136+
func setUserId(_ userId: String?, authToken: String? = nil, onCompletion: OnCompletionHandler? = nil) {
137137
ITBInfo()
138138

139139
if _userId == userId && userId != nil && authToken != nil {
@@ -149,7 +149,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
149149

150150
_email = nil
151151
_userId = userId
152-
self.resultCallback = resultCallback
152+
_resultCallback = onCompletion
153153

154154
storeIdentifierData()
155155

@@ -168,7 +168,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
168168
guard let appName = pushIntegrationName else {
169169
let errorMessage = "Not registering device token - appName must not be nil"
170170
ITBError(errorMessage)
171-
self.resultCallback?(false)
171+
_resultCallback?(false)
172172
onFailure?(errorMessage, nil)
173173
return
174174
}
@@ -184,11 +184,11 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
184184
requestHandler.register(registerTokenInfo: registerTokenInfo,
185185
notificationStateProvider: notificationStateProvider,
186186
onSuccess: { (_ data: [AnyHashable: Any]?) in
187-
self.resultCallback?(true)
187+
_resultCallback?(true)
188188
onSuccess?(data)
189189
},
190190
onFailure: { (_ reason: String?, _ data: Data?) in
191-
self.resultCallback?(false)
191+
_resultCallback?(false)
192192
onFailure?(reason, data)
193193
}
194194
)
@@ -420,7 +420,6 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
420420

421421
private var config: IterableConfig
422422
private var apiEndPoint: String
423-
private var resultCallback: ((Bool) -> Void)? = nil
424423

425424
/// Following are needed for handling pending notification and deep link.
426425
static var pendingNotificationResponse: NotificationResponseProtocol?
@@ -438,6 +437,8 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
438437
private var _email: String?
439438
private var _payloadData: [AnyHashable: Any]?
440439
private var _userId: String?
440+
private var _resultCallback: OnCompletionHandler? = nil
441+
441442

442443
/// the hex representation of this device token
443444
private var hexToken: String?
@@ -548,7 +549,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
548549
if config.autoPushRegistration {
549550
notificationStateProvider.registerForRemoteNotifications()
550551
} else {
551-
self.resultCallback?(true)
552+
_resultCallback?(true)
552553
}
553554

554555
_ = inAppManager.scheduleSync()

swift-sdk/IterableAPI.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ public final class IterableAPI: NSObject {
130130

131131
// MARK: - SDK
132132

133-
public static func setEmail(_ email: String?, _ authToken: String? = nil, _ resultCallback: ((Bool) -> Void)? = nil) {
134-
internalImplementation?.setEmail(email, authToken: authToken, resultCallback: resultCallback)
133+
public static func setEmail(_ email: String?, _ authToken: String? = nil, _ onCompletion: OnCompletionHandler? = nil) {
134+
internalImplementation?.setEmail(email, authToken: authToken, onCompletion: onCompletion)
135135
}
136136

137-
public static func setUserId(_ userId: String?, _ authToken: String? = nil, _ resultCallback: ((Bool) -> Void)? = nil) {
138-
internalImplementation?.setUserId(userId, authToken: authToken, resultCallback: resultCallback)
137+
public static func setUserId(_ userId: String?, _ authToken: String? = nil, _ onCompletion: OnCompletionHandler? = nil) {
138+
internalImplementation?.setUserId(userId, authToken: authToken, onCompletion: onCompletion)
139139
}
140140

141141
/// Handle a Universal Link

tests/unit-tests/IterableAPITests.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ class IterableAPITests: XCTestCase {
173173
let networkSession = MockNetworkSession(statusCode: 200)
174174
let internalAPI = InternalIterableAPI.initializeForTesting(apiKey: IterableAPITests.apiKey, config: config, networkSession: networkSession)
175175

176-
internalAPI.setEmail("[email protected]") { error in
177-
XCTAssertNil(error)
176+
internalAPI.setEmail("[email protected]") { success in
177+
XCTAssertNotNil(success)
178178
expectation.fulfill()
179179
}
180180

@@ -190,7 +190,6 @@ class IterableAPITests: XCTestCase {
190190

191191
internalAPI.setEmail("invalid_email") { error in
192192
XCTAssertNotNil(error)
193-
XCTAssertEqual(error?.localizedDescription, "Invalid email address")
194193
expectation.fulfill()
195194
}
196195

@@ -204,8 +203,8 @@ class IterableAPITests: XCTestCase {
204203
let networkSession = MockNetworkSession(statusCode: 200)
205204
let internalAPI = InternalIterableAPI.initializeForTesting(apiKey: IterableAPITests.apiKey, config: config, networkSession: networkSession)
206205

207-
internalAPI.setUserId("user123") { error in
208-
XCTAssertNil(error)
206+
internalAPI.setUserId("user123") { success in
207+
XCTAssertNil(success)
209208
expectation.fulfill()
210209
}
211210

0 commit comments

Comments
 (0)