Created
February 25, 2018 06:52
-
-
Save yingmu52/56226efd890f5fca57e28b1f6692c3e9 to your computer and use it in GitHub Desktop.
Deep Linking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Route { | |
case modal | |
case tab(TabBarViewController.Tab) | |
init?(url: URL) { | |
switch url.absoluteString { | |
case "\(scheme)://tab1": self = .tab(.tab1) | |
case "\(scheme)://tab2": self = .tab(.tab2) | |
case "\(scheme)://modal": self = .modal | |
default: return nil | |
} | |
} | |
init?(shortcutItem: UIApplicationShortcutItem) { | |
switch shortcutItem.type { | |
case "io.objc.deeplinking.tab1": self = .tab(.tab1) | |
case "io.objc.deeplinking.tab2": self = .tab(.tab2) | |
case "io.objc.deeplinking.modal": self = .modal | |
default: return nil | |
} | |
} | |
func handle(_ delegate: UIResponder & UIApplicationDelegate) { | |
let tabController = delegate.window??.rootViewController as! TabBarViewController | |
switch self { | |
case .tab(let tab): tabController.showTab(tab) | |
case .modal: tabController.showModal(sender: self) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment