@@ -258,6 +258,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
258
258
func register( token: Data ,
259
259
onSuccess: OnSuccessHandler ? = nil ,
260
260
onFailure: OnFailureHandler ? = nil ) {
261
+
261
262
guard let appName = pushIntegrationName else {
262
263
let errorMessage = " Not registering device token - appName must not be nil "
263
264
ITBError ( errorMessage)
@@ -574,7 +575,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
574
575
source: InAppDeleteSource ? = nil ,
575
576
inboxSessionId: String ? = nil ,
576
577
onSuccess: OnSuccessHandler ? = nil ,
577
- onFailure: OnFailureHandler ? = nil ) -> Pending < SendRequestValue , SendRequestError > {
578
+ onFailure: OnFailureHandler ? = nil ) -> Pending < SendRequestValue , SendRequestError > {
578
579
requestHandler. inAppConsume ( message: message,
579
580
location: location,
580
581
source: source,
@@ -699,6 +700,17 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
699
700
}
700
701
}
701
702
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
+
702
714
public func isEitherUserIdOrEmailSet( ) -> Bool {
703
715
IterableUtil . isNotNullOrEmpty ( string: _email) || IterableUtil . isNotNullOrEmpty ( string: _userId)
704
716
}
@@ -710,9 +722,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
710
722
private func logoutPreviousUser( ) {
711
723
ITBInfo ( )
712
724
713
- guard isEitherUserIdOrEmailSet ( ) else {
714
- return
715
- }
725
+ guard isSDKInitialized ( ) else { return }
716
726
717
727
if config. autoPushRegistration {
718
728
disableDeviceForCurrentUser ( )
@@ -737,10 +747,12 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
737
747
}
738
748
739
749
private func onLogin( _ authToken: String ? = nil , onloginSuccess onloginSuccessCallBack: ( ( ) -> ( ) ) ? = nil ) {
750
+ guard isSDKInitialized ( ) else { return }
751
+
740
752
ITBInfo ( )
741
753
742
754
self . authManager. pauseAuthRetries ( false )
743
- if let authToken = authToken {
755
+ if let authToken {
744
756
self . authManager. setNewToken ( authToken)
745
757
completeUserLogin ( onloginSuccessCallBack: onloginSuccessCallBack)
746
758
} else if isEitherUserIdOrEmailSet ( ) && config. authDelegate != nil {
@@ -761,10 +773,8 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
761
773
}
762
774
763
775
private func completeUserLogin( onloginSuccessCallBack: ( ( ) -> ( ) ) ? = nil ) {
764
- ITBInfo ( )
765
- guard isEitherUserIdOrEmailSet ( ) else {
766
- return
767
- }
776
+ ITBInfo ( )
777
+ guard isSDKInitialized ( ) else { return }
768
778
769
779
if config. autoPushRegistration {
770
780
notificationStateProvider. registerForRemoteNotifications ( )
0 commit comments