Skip to content

Instantly share code, notes, and snippets.

@azimin
Last active January 19, 2017 00:17
Show Gist options
  • Save azimin/b2ed749732b0a677d914 to your computer and use it in GitHub Desktop.
Save azimin/b2ed749732b0a677d914 to your computer and use it in GitHub Desktop.
Method that handle UIApplicationShortcutItem and select tab from its info
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
let handled = handleShortcutItem(shortcutItem)
completionHandler(handled)
}
func handleShortcutItem(_ shortcutItem: UIApplicationShortcutItem) -> Bool {
if shortcutItem.type != basicShortcutTypeString {
return false
}
if let index = shortcutItem.userInfo?["TabIndex"] as? Int {
(window?.rootViewController as? UITabBarController)?.selectedIndex = index
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment