diff --git a/WooCommerce/Classes/AppDelegate.swift b/WooCommerce/Classes/AppDelegate.swift index 2fea14fc34e..40b498ebf98 100644 --- a/WooCommerce/Classes/AppDelegate.swift +++ b/WooCommerce/Classes/AppDelegate.swift @@ -54,16 +54,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // Setup Components setupStartupWaitingTimeTracker() - let stores = ServiceLocator.stores let analytics = ServiceLocator.analytics let pushNotesManager = ServiceLocator.pushNotesManager - stores.initializeAfterDependenciesAreInitialized() setupAnalytics(analytics) + ServiceLocator.authenticationManager.initialize() + ServiceLocator.stores.initializeAfterDependenciesAreInitialized() setupCocoaLumberjack() setupLibraryLogger() setupLogLevel(.verbose) - setupPushNotificationsManagerIfPossible(pushNotesManager, stores: stores) + setupPushNotificationsManagerIfPossible(pushNotesManager) setupAppRatingManager() setupWormholy() setupKeyboardStateProvider() @@ -268,7 +268,7 @@ extension AppDelegate { /// Push Notifications: Authorization + Registration! /// // periphery: ignore - Fails when build on simulator - func setupPushNotificationsManagerIfPossible(_ pushNotesManager: PushNotesManager, stores: StoresManager) { + func setupPushNotificationsManagerIfPossible(_ pushNotesManager: PushNotesManager) { #if targetEnvironment(simulator) DDLogVerbose("👀 Push Notifications are not supported in the Simulator!") #else @@ -417,7 +417,7 @@ extension AppDelegate { /// Runs whenever the Authentication Flow is completed successfully. /// func authenticatorWasDismissed() { - setupPushNotificationsManagerIfPossible(ServiceLocator.pushNotesManager, stores: ServiceLocator.stores) + setupPushNotificationsManagerIfPossible(ServiceLocator.pushNotesManager) requirementsChecker.checkEligibilityForDefaultStore() } } diff --git a/WooCommerce/Classes/Authentication/AuthenticationManager.swift b/WooCommerce/Classes/Authentication/AuthenticationManager.swift index b553be3e604..2eaaf4aebb3 100644 --- a/WooCommerce/Classes/Authentication/AuthenticationManager.swift +++ b/WooCommerce/Classes/Authentication/AuthenticationManager.swift @@ -65,6 +65,8 @@ class AuthenticationManager: Authentication { private let userDefaults: UserDefaults + private var initialized: Bool = false + init(stores: StoresManager = ServiceLocator.stores, storageManager: StorageManagerType = ServiceLocator.storageManager, featureFlagService: FeatureFlagService = ServiceLocator.featureFlagService, @@ -84,6 +86,8 @@ class AuthenticationManager: Authentication { /// Initializes the WordPress Authenticator. /// func initialize() { + guard !initialized else { return } + initialized = true WordPressAuthenticator.initializeWithCustomConfigs() WordPressAuthenticator.shared.delegate = self }