How to use AppFlowController in iOS

Issue #364

AppFlowController.swift

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import UIKit
import GoogleMaps
import Stripe

final class AppFlowController: UIViewController {
private lazy var window = UIWindow(frame: UIScreen.main.bounds)

func configure() {
GMSServices.provideAPIKey(Constant.googleMapsApiKey)
STPPaymentConfiguration.shared().publishableKey = Constant.stripeKey
}

func start() {
if Deps.onboardingHandler.hasOnboarded {
startMain()
} else {
startOnboarding()
}

window.makeKeyAndVisible()
}

func startOnboarding() {
let controller = OnboardingController()
controller.delegate = self
window.rootViewController = controller
}

func startMain() {
let controller = MainFlowController()
window.rootViewController = controller
controller.start()
}
}

extension AppFlowController: OnboardingControllerDelegate {
func onboardingControllerDidFinish(_ controller: OnboardingController) {
Deps.onboardingHandler.hasOnboarded = true
startMain()
}
}

AppDelegate.swift

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

private let appFlowController = AppFlowController()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

appFlowController.configure()
appFlowController.start()

UIApplication.shared.registerForRemoteNotifications()
FirebaseApp.configure()
return true
}
}

Comments