Linking 3D Touch Static Shortcuts To Tabbed/Navigation View Controllers In Swift 4

In this example, I have a Swift 4 app with a single Tab Bar Controller and three Navigation Controllers each segued to a View Controller. There are plenty of guides online to help you set up the necessary strings in your Info.plist to enable static 3D touch shortcuts. In my case, I have three shortcuts – each is linked to a different view controller.

Place the following function into your AppDelegate.swift file.

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void)
        guard let tabBarController = window?.rootViewController as? UITabBarController else 
        switch shortcutItem.type 
        case "UIApplicationShortcutItemType-0":
            tabBarController.selectedIndex = 0
        case "UIApplicationShortcutItemType-1":
            tabBarController.selectedIndex = 1
        case "UIApplicationShortcutItemType-2":
            tabBarController.selectedIndex = 2

The bold code should match the UIApplicationShortcutItemType you placed in Info.plist for each shortcut. 🙂



My posts do NOT constitute medical advice nor do they reflect the views of the institutions and organizations I'm affiliated with. Please read this site's Disclaimer and Terms of Use for more information.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *