Skip to content

Commit 49eb8f3

Browse files
authored
Merge branch 'feature/itbl_track_anon_user' into feature/MOB-9746-Use-destinationUser-JWT-when-calling-merge
2 parents 02e1f42 + 9a26368 commit 49eb8f3

File tree

2 files changed

+168
-62
lines changed

2 files changed

+168
-62
lines changed

swift-sdk/Internal/InternalIterableAPI.swift

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
258258
func register(token: Data,
259259
onSuccess: OnSuccessHandler? = nil,
260260
onFailure: OnFailureHandler? = nil) {
261+
261262
guard let appName = pushIntegrationName else {
262263
let errorMessage = "Not registering device token - appName must not be nil"
263264
ITBError(errorMessage)
@@ -574,7 +575,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
574575
source: InAppDeleteSource? = nil,
575576
inboxSessionId: String? = nil,
576577
onSuccess: OnSuccessHandler? = nil,
577-
onFailure: OnFailureHandler? = nil) -> Pending<SendRequestValue, SendRequestError> {
578+
onFailure: OnFailureHandler? = nil) -> Pending<SendRequestValue, SendRequestError> {
578579
requestHandler.inAppConsume(message: message,
579580
location: location,
580581
source: source,
@@ -699,6 +700,17 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
699700
}
700701
}
701702

703+
704+
func isSDKInitialized() -> Bool {
705+
let isInitialized = !apiKey.isEmpty && isEitherUserIdOrEmailSet()
706+
707+
if !isInitialized {
708+
ITBInfo("Iterable SDK must be initialized with an API key and user email/userId before calling SDK methods")
709+
}
710+
711+
return isInitialized
712+
}
713+
702714
public func isEitherUserIdOrEmailSet() -> Bool {
703715
IterableUtil.isNotNullOrEmpty(string: _email) || IterableUtil.isNotNullOrEmpty(string: _userId)
704716
}
@@ -710,9 +722,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
710722
private func logoutPreviousUser() {
711723
ITBInfo()
712724

713-
guard isEitherUserIdOrEmailSet() else {
714-
return
715-
}
725+
guard isSDKInitialized() else { return }
716726

717727
if config.autoPushRegistration {
718728
disableDeviceForCurrentUser()
@@ -737,10 +747,12 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
737747
}
738748

739749
private func onLogin(_ authToken: String? = nil, onloginSuccess onloginSuccessCallBack: (()->())? = nil) {
750+
guard isSDKInitialized() else { return }
751+
740752
ITBInfo()
741753

742754
self.authManager.pauseAuthRetries(false)
743-
if let authToken = authToken {
755+
if let authToken {
744756
self.authManager.setNewToken(authToken)
745757
completeUserLogin(onloginSuccessCallBack: onloginSuccessCallBack)
746758
} else if isEitherUserIdOrEmailSet() && config.authDelegate != nil {
@@ -761,10 +773,8 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
761773
}
762774

763775
private func completeUserLogin(onloginSuccessCallBack: (()->())? = nil) {
764-
ITBInfo()
765-
guard isEitherUserIdOrEmailSet() else {
766-
return
767-
}
776+
ITBInfo()
777+
guard isSDKInitialized() else { return }
768778

769779
if config.autoPushRegistration {
770780
notificationStateProvider.registerForRemoteNotifications()

0 commit comments

Comments
 (0)