diff --git a/iOS/BattleBuddy/Info.plist b/iOS/BattleBuddy/Info.plist index c2ae719..e0da1fa 100644 --- a/iOS/BattleBuddy/Info.plist +++ b/iOS/BattleBuddy/Info.plist @@ -60,6 +60,23 @@ NSAllowsArbitraryLoadsInWebContent + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + + + + UILaunchStoryboardName LaunchScreen UIRequiredDeviceCapabilities @@ -67,7 +84,7 @@ armv7 UIRequiresFullScreen - + UIStatusBarStyle UIStatusBarStyleDefault UISupportedInterfaceOrientations diff --git a/iOS/BattleBuddy/Source/Infrastructure/AppDelegate.swift b/iOS/BattleBuddy/Source/Infrastructure/AppDelegate.swift index 46218db..d8be245 100644 --- a/iOS/BattleBuddy/Source/Infrastructure/AppDelegate.swift +++ b/iOS/BattleBuddy/Source/Infrastructure/AppDelegate.swift @@ -14,9 +14,11 @@ import Crashlytics @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, SessionDelegate { + var window: UIWindow? let tabBarController = BaseTabBarController() let dependencyManager = DependencyManagerImpl.shared + var hasSessionFinishedLaunching: Bool = false override init() { super.init() @@ -24,12 +26,62 @@ class AppDelegate: UIResponder, UIApplicationDelegate, SessionDelegate { dependencyManager.assembleDependencies(self) } - func applicationDidFinishLaunching(_ application: UIApplication) { + // UIApplicationDelegate + + func applicationDidFinishLaunching(_ application: UIApplication) { + if #available(iOS 13.0, *) { + setupApplication() + return + } + self.window = UIWindow.init(frame: UIScreen.main.bounds) self.window?.backgroundColor = UIColor.Theme.background self.window?.rootViewController = LoadingViewController() defer { self.window?.makeKeyAndVisible() } + setupApplication() + } + + func applicationDidBecomeActive(_ application: UIApplication) { + // dependencyManager.twitchManager().refreshTwitchInfo() TODO: UPDATE FOR NEW TWITCH API + dependencyManager.metadataManager().updateGlobalMetadata { (globalMetadata) -> Void in } + } + + @available(iOS 13.0, *) + func sceneDidBecomeActive(_ scene: UIScene) { + // dependencyManager.twitchManager().refreshTwitchInfo() TODO: UPDATE FOR NEW TWITCH API + dependencyManager.metadataManager().updateGlobalMetadata { (globalMetadata) -> Void in } + } + + // SessionDelegate + + func sessionDidFinishLoading() { + reloadRootViewController() + dependencyManager.feedbackManager().promptForReviewIfNecessary() + + hasSessionFinishedLaunching = true + } + + // Internal + + func reloadRootViewController() { + if #available(iOS 13.0, *) { + for scene in UIApplication.shared.connectedScenes { + guard let sceneDelegate = scene.delegate as? SceneDelegate else { + continue + } + + sceneDelegate.reloadRootViewController() + } + } else { + self.tabBarController.setup() + self.window?.rootViewController = self.tabBarController + } + } + + // Private + + private func setupApplication() { // If we're running unit tests, bail out here as we don't want any // more real app-launch stuff to be processed. guard NSClassFromString("XCTestCase") == nil else { return } @@ -38,15 +90,52 @@ class AppDelegate: UIResponder, UIApplicationDelegate, SessionDelegate { dependencyManager.accountManager().initializeSession() Fabric.with([Crashlytics.self]) } +} - // SessionDelegate - func sessionDidFinishLoading() { - reloadRootViewController() - dependencyManager.feedbackManager().promptForReviewIfNecessary() +@available(iOS 13.0, *) +class SceneDelegate: UIResponder, UISceneDelegate { + + var window: UIWindow? + + // UISceneDelegate + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + guard let windowScene = (scene as? UIWindowScene) else { return } + + let window = UIWindow(windowScene: windowScene) + self.window = window + defer { window.makeKeyAndVisible() } + + window.backgroundColor = UIColor.Theme.background + + if + let appDelegate = UIApplication.shared.delegate as? AppDelegate, + appDelegate.hasSessionFinishedLaunching + { + reloadRootViewController() + } else { + window.rootViewController = LoadingViewController() + } } + // Internal + func reloadRootViewController() { + guard let window = window else { + return + } + + let tabBarController = BaseTabBarController() + tabBarController.setup() + window.rootViewController = tabBarController + } +} + + +fileprivate extension BaseTabBarController { + + func setup() { let itemsVC = ItemsMenuViewController() itemsVC.title = "items".local() itemsVC.tabBarItem.image = UIImage(named: "items") @@ -62,12 +151,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, SessionDelegate { moreVC.tabBarItem.image = UIImage(named: "more") let moreNC = BaseNavigationController(rootViewController: moreVC) - self.tabBarController.setViewControllers([itemsNC, learnNC, moreNC], animated: false) - self.window?.rootViewController = self.tabBarController - } - - func applicationDidBecomeActive(_ application: UIApplication) { - // dependencyManager.twitchManager().refreshTwitchInfo() TODO: UPDATE FOR NEW TWITCH API - dependencyManager.metadataManager().updateGlobalMetadata { (globalMetadata) -> Void in } + setViewControllers([itemsNC, learnNC, moreNC], animated: false) } } diff --git a/iOS/BattleBuddy/Source/Infrastructure/Service Locator/DependencyInterfaces.swift b/iOS/BattleBuddy/Source/Infrastructure/Service Locator/DependencyInterfaces.swift index 345e918..a8e598d 100644 --- a/iOS/BattleBuddy/Source/Infrastructure/Service Locator/DependencyInterfaces.swift +++ b/iOS/BattleBuddy/Source/Infrastructure/Service Locator/DependencyInterfaces.swift @@ -12,7 +12,7 @@ import UIKit protocol DependencyManager { static var shared: DependencyManager { get } - func assembleDependencies(_ appDelegate: AppDelegate) + func assembleDependencies(_ appDelegate: SessionDelegate) func pushNotificationManager() -> PushNotificationManager func accountManager() -> AccountManager func databaseManager() -> DatabaseManager diff --git a/iOS/BattleBuddy/Source/Infrastructure/Service Locator/DependencyManagerImpl.swift b/iOS/BattleBuddy/Source/Infrastructure/Service Locator/DependencyManagerImpl.swift index 6e1dff2..8a1faf3 100644 --- a/iOS/BattleBuddy/Source/Infrastructure/Service Locator/DependencyManagerImpl.swift +++ b/iOS/BattleBuddy/Source/Infrastructure/Service Locator/DependencyManagerImpl.swift @@ -24,7 +24,7 @@ class DependencyManagerImpl: DependencyManager { var deviceMngr: DeviceManager? var localeMngr: LocaleManager? - func assembleDependencies(_ appDelegate: AppDelegate) { + func assembleDependencies(_ appDelegate: SessionDelegate) { // Firebase handles sessions, accounts, storage, and metadata let firebase = FirebaseManager(sessionDelegate: appDelegate) pushNotificationMngr = firebase diff --git a/iOS/Podfile.lock b/iOS/Podfile.lock index 4224661..1a4746a 100644 --- a/iOS/Podfile.lock +++ b/iOS/Podfile.lock @@ -207,8 +207,8 @@ SPEC REPOS: SPEC CHECKSUMS: Alamofire: ae5c501addb7afdbb13687d7f2f722c78734c2d3 BoringSSL-GRPC: db8764df3204ccea016e1c8dd15d9a9ad63ff318 - Crashlytics: 2dfd686bcb918dc10ee0e76f7f853fe42c7bd552 - Fabric: 706c8b8098fff96c33c0db69cbf81f9c551d0d74 + Crashlytics: d3e5090419ddee1003192c98ac0e6dfdb1dba266 + Fabric: ea977e3cd9c20425516d3dafd3bf8c941c51223f Firebase: c35912a5c160193dc423f260dac3f167a1a795ab FirebaseAnalytics: 843c7f64a8f9c79f0d03281197ebe7bb1d58d477 FirebaseAnalyticsInterop: d48b6ab67bcf016a05e55b71fc39c61c0cb6b7f3 @@ -239,4 +239,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 2a1a1bb9323cfcc2df93630a749109aa521a46e0 -COCOAPODS: 1.9.3 +COCOAPODS: 1.11.2