Last active
August 30, 2020 00:51
-
-
Save laevandus/11205f31ee3f61c61441ccc8ce80d8cb to your computer and use it in GitHub Desktop.
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
extension UIApplicationShortcutItem { | |
enum Action: String { | |
case addPlant | |
case showPlant | |
} | |
} | |
final class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { | |
guard let identifier = UIApplicationShortcutItem.Action(rawValue: shortcutItem.type) else { fatalError("Unknown shortcut") } | |
switch identifier { | |
case .addPlant: | |
flowCoordinator?.plantListViewModel.isPresentingAddPlant = true | |
case .showPlant: | |
print("show plant: \(String(describing: shortcutItem.userInfo))") | |
} | |
completionHandler(true) | |
} | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | |
// … | |
// Triggering the add plant shortcut when launching the app | |
if connectionOptions.shortcutItem?.type == UIApplicationShortcutItem.Action.addPlant.rawValue { | |
viewModel.isPresentingAddPlant = true | |
} | |
// Setting up a view with the view model configured to show add plant view | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment