I am having an issue using the 3D touch shortcuts inside my application. My app uses tabs but I would like to redirect the user into a tab then also into another segue when they press the create wish list button.
Here is a picture of my storyboard.
The code I am using at the moment displays the home view controller but I would like it to go into the create wish list controller.
The code I have for the handle shortcut inside the app delegate is here:
func handleShortcut( shortcutItem:UIApplicationShortcutItem ) -> Bool {
print("Handling shortcut")
var succeeded = false
if( shortcutItem.type == "com.example.Giftr" ) {
print("- Handling \(shortcutItem.type)")
if let tabVC = self.window?.rootViewController as? UITabBarController{
tabVC.selectedIndex = 1
//This is where I need to swap to the "createwishlist" view controller.
}
To solve this I used a Global Variable to store that the shortcut had been taken inside the appDelegate like below.
GlobalVars.shortcut = 1
let tabVC = window?.rootViewController as! UITabBarController
print(tabVC.self)
tabVC.selectedIndex = 0
Then inside the controller of the tab for the selectedIndex 0 checked if that value was 1 and if it was then segued to the view controller that I wanted to end up at. Like shown.
override func viewDidAppear(animated: Bool) {
if(GlobalVars.shortcut == 1)
{
self.performSegueWithIdentifier("shortcut", sender: self)
GlobalVars.shortcut = 0
}
}
Make sure that you set the Global Variable to 0 or this will be called every time the view appears.