@@ -250,6 +250,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
250
250
func register( token: Data ,
251
251
onSuccess: OnSuccessHandler ? = nil ,
252
252
onFailure: OnFailureHandler ? = nil ) {
253
+
253
254
guard let appName = pushIntegrationName else {
254
255
let errorMessage = " Not registering device token - appName must not be nil "
255
256
ITBError ( errorMessage)
@@ -566,7 +567,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
566
567
source: InAppDeleteSource ? = nil ,
567
568
inboxSessionId: String ? = nil ,
568
569
onSuccess: OnSuccessHandler ? = nil ,
569
- onFailure: OnFailureHandler ? = nil ) -> Pending < SendRequestValue , SendRequestError > {
570
+ onFailure: OnFailureHandler ? = nil ) -> Pending < SendRequestValue , SendRequestError > {
570
571
requestHandler. inAppConsume ( message: message,
571
572
location: location,
572
573
source: source,
@@ -691,6 +692,17 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
691
692
}
692
693
}
693
694
695
+
696
+ func isSDKInitialized( ) -> Bool {
697
+ let isInitialized = !apiKey. isEmpty && isEitherUserIdOrEmailSet ( )
698
+
699
+ if !isInitialized {
700
+ ITBInfo ( " Iterable SDK must be initialized with an API key and user email/userId before calling SDK methods " )
701
+ }
702
+
703
+ return isInitialized
704
+ }
705
+
694
706
public func isEitherUserIdOrEmailSet( ) -> Bool {
695
707
IterableUtil . isNotNullOrEmpty ( string: _email) || IterableUtil . isNotNullOrEmpty ( string: _userId)
696
708
}
@@ -702,9 +714,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
702
714
private func logoutPreviousUser( ) {
703
715
ITBInfo ( )
704
716
705
- guard isEitherUserIdOrEmailSet ( ) else {
706
- return
707
- }
717
+ guard isSDKInitialized ( ) else { return }
708
718
709
719
if config. autoPushRegistration {
710
720
disableDeviceForCurrentUser ( )
@@ -729,10 +739,12 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
729
739
}
730
740
731
741
private func onLogin( _ authToken: String ? = nil ) {
742
+ guard isSDKInitialized ( ) else { return }
743
+
732
744
ITBInfo ( )
733
745
734
746
self . authManager. pauseAuthRetries ( false )
735
- if let authToken = authToken {
747
+ if let authToken {
736
748
self . authManager. setNewToken ( authToken)
737
749
completeUserLogin ( )
738
750
} else if isEitherUserIdOrEmailSet ( ) && config. authDelegate != nil {
@@ -755,9 +767,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
755
767
private func completeUserLogin( ) {
756
768
ITBInfo ( )
757
769
758
- guard isEitherUserIdOrEmailSet ( ) else {
759
- return
760
- }
770
+ guard isSDKInitialized ( ) else { return }
761
771
762
772
if config. autoPushRegistration {
763
773
notificationStateProvider. registerForRemoteNotifications ( )
0 commit comments