Skip to content

Commit b17868a

Browse files
authored
MOB-10770 Update iOS SDK initialization checks (#891)
1 parent 10e8f47 commit b17868a

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

swift-sdk/Internal/InternalIterableAPI.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
227227
return SendRequestError.createErroredFuture(reason: errorMessage)
228228
}
229229

230-
guard userId != nil || email != nil else {
230+
guard isEitherUserIdOrEmailSet() else {
231231
let errorMessage = "either userId or email must be present"
232232
onFailure?(errorMessage, nil)
233233
return SendRequestError.createErroredFuture(reason: errorMessage)
@@ -559,16 +559,28 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
559559
}
560560
}
561561

562-
private func isEitherUserIdOrEmailSet() -> Bool {
562+
func isSDKInitialized() -> Bool {
563+
let isInitialized = !apiKey.isEmpty && isEitherUserIdOrEmailSet()
564+
565+
if !isInitialized {
566+
ITBInfo("Iterable SDK must be initialized with an API key and user email/userId before calling SDK methods")
567+
}
568+
569+
return isInitialized
570+
}
571+
572+
public func isEitherUserIdOrEmailSet() -> Bool {
563573
IterableUtil.isNotNullOrEmpty(string: _email) || IterableUtil.isNotNullOrEmpty(string: _userId)
564574
}
565575

576+
public func noUserLoggedIn() -> Bool {
577+
IterableUtil.isNullOrEmpty(string: _email) && IterableUtil.isNullOrEmpty(string: _userId)
578+
}
579+
566580
private func logoutPreviousUser() {
567581
ITBInfo()
568582

569-
guard isEitherUserIdOrEmailSet() else {
570-
return
571-
}
583+
guard isSDKInitialized() else { return }
572584

573585
if config.autoPushRegistration {
574586
disableDeviceForCurrentUser()
@@ -595,6 +607,8 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
595607
private func onLogin(_ authToken: String? = nil) {
596608
ITBInfo()
597609

610+
guard isSDKInitialized() else { return }
611+
598612
self.authManager.pauseAuthRetries(false)
599613
if let authToken = authToken {
600614
self.authManager.setNewToken(authToken)
@@ -618,10 +632,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
618632

619633
private func completeUserLogin() {
620634
ITBInfo()
621-
622-
guard isEitherUserIdOrEmailSet() else {
623-
return
624-
}
635+
guard isSDKInitialized() else { return }
625636

626637
if config.autoPushRegistration {
627638
notificationStateProvider.registerForRemoteNotifications()

0 commit comments

Comments
 (0)