forked from CassiusPacheco/iOS-Routing-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneDelegate.swift
More file actions
46 lines (38 loc) · 1.61 KB
/
Copy pathSceneDelegate.swift
File metadata and controls
46 lines (38 loc) · 1.61 KB
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
42
43
44
45
46
//
// SceneDelegate.swift
// RoutingExample
//
// Created by Cassius Pacheco on 7/3/20.
// Copyright © 2020 Cassius Pacheco. All rights reserved.
//
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
private var deeplinkRouter: Router?
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
let mainRouter = DefaultRouter(rootTransition: EmptyTransition())
let tabs = [mainRouter.makeShopTab(), mainRouter.makeWishlistTab()]
window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
window?.rootViewController = MainTabBarController(viewControllers: tabs)
window?.makeKeyAndVisible()
if let urlContext = connectionOptions.urlContexts.first {
deeplink(urlContext.url)
}
}
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let urlContext = URLContexts.first else { return }
deeplink(urlContext.url)
}
private func deeplink(_ url: URL) {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
// Define all deeplinks to be opened with a Modal Transition
let transition = ModalTransition()
let router = DeeplinkRouter(rootTransition: transition)
router.root = self.window?.topMostViewController()
router.route(to: url, as: transition)
self.deeplinkRouter = router
}
}
}