@@ -227,7 +227,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
227
227
return SendRequestError . createErroredFuture ( reason: errorMessage)
228
228
}
229
229
230
- guard userId != nil || email != nil else {
230
+ guard isEitherUserIdOrEmailSet ( ) else {
231
231
let errorMessage = " either userId or email must be present "
232
232
onFailure ? ( errorMessage, nil )
233
233
return SendRequestError . createErroredFuture ( reason: errorMessage)
@@ -559,16 +559,28 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
559
559
}
560
560
}
561
561
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 {
563
573
IterableUtil . isNotNullOrEmpty ( string: _email) || IterableUtil . isNotNullOrEmpty ( string: _userId)
564
574
}
565
575
576
+ public func noUserLoggedIn( ) -> Bool {
577
+ IterableUtil . isNullOrEmpty ( string: _email) && IterableUtil . isNullOrEmpty ( string: _userId)
578
+ }
579
+
566
580
private func logoutPreviousUser( ) {
567
581
ITBInfo ( )
568
582
569
- guard isEitherUserIdOrEmailSet ( ) else {
570
- return
571
- }
583
+ guard isSDKInitialized ( ) else { return }
572
584
573
585
if config. autoPushRegistration {
574
586
disableDeviceForCurrentUser ( )
@@ -595,6 +607,8 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
595
607
private func onLogin( _ authToken: String ? = nil ) {
596
608
ITBInfo ( )
597
609
610
+ guard isSDKInitialized ( ) else { return }
611
+
598
612
self . authManager. pauseAuthRetries ( false )
599
613
if let authToken = authToken {
600
614
self . authManager. setNewToken ( authToken)
@@ -618,10 +632,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
618
632
619
633
private func completeUserLogin( ) {
620
634
ITBInfo ( )
621
-
622
- guard isEitherUserIdOrEmailSet ( ) else {
623
- return
624
- }
635
+ guard isSDKInitialized ( ) else { return }
625
636
626
637
if config. autoPushRegistration {
627
638
notificationStateProvider. registerForRemoteNotifications ( )
0 commit comments