Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOB-10770 Update iOS SDK initialization checks #891

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions swift-sdk/Internal/InternalIterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
return SendRequestError.createErroredFuture(reason: errorMessage)
}

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

private func isEitherUserIdOrEmailSet() -> Bool {
func isSDKInitialized() -> Bool {
let isInitialized = !apiKey.isEmpty && isEitherUserIdOrEmailSet()

if !isInitialized {
ITBInfo("Iterable SDK must be initialized with an API key and user email/userId before calling SDK methods")
}

return isInitialized
}

public func isEitherUserIdOrEmailSet() -> Bool {
IterableUtil.isNotNullOrEmpty(string: _email) || IterableUtil.isNotNullOrEmpty(string: _userId)
}

public func noUserLoggedIn() -> Bool {
IterableUtil.isNullOrEmpty(string: _email) && IterableUtil.isNullOrEmpty(string: _userId)
}

private func logoutPreviousUser() {
ITBInfo()

guard isEitherUserIdOrEmailSet() else {
return
}
guard isSDKInitialized() else { return }

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

guard isSDKInitialized() else { return }

self.authManager.pauseAuthRetries(false)
if let authToken = authToken {
self.authManager.setNewToken(authToken)
Expand All @@ -618,10 +632,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {

private func completeUserLogin() {
ITBInfo()

guard isEitherUserIdOrEmailSet() else {
return
}
guard isSDKInitialized() else { return }

if config.autoPushRegistration {
notificationStateProvider.registerForRemoteNotifications()
Expand Down
Loading