2017-04-02 3 views
0

Hey Leute, also meine 3D-Touch-Shortcuts, die ich in meine Info.plist zeige, aber wenn ich sie auswähle, nimmt nur der, der zuerst in meinem Code erscheint, den View-Controller an. Die anderen funktionieren einfach nicht (bringen Sie mich zu der von mir angegebenen Ansicht).3D Touch statische Shortcuts

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { 
    if shortcutItem.type == "com.amansk.software" { 
     self.window = UIWindow(frame: UIScreen.main.bounds) 
     let storyboard = UIStoryboard(name: "Main", bundle: nil) 
     let initialViewController = storyboard.instantiateViewController(withIdentifier: "sw") 
     self.window?.rootViewController = initialViewController 
     self.window?.makeKeyAndVisible() 

     if shortcutItem.type == "com.amansk.hardware" { 
      self.window = UIWindow(frame: UIScreen.main.bounds) 
      let storyboard = UIStoryboard(name: "Main", bundle: nil) 
      let initialViewController = storyboard.instantiateViewController(withIdentifier: "hw") 
      self.window?.rootViewController = initialViewController 
      self.window?.makeKeyAndVisible() 
     } 
    } 
} 

Antwort

1

Die zweite if-AnweisungOUTSIDE des ersten

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { 
    if shortcutItem.type == "com.amansk.software" { 
     self.window = UIWindow(frame: UIScreen.main.bounds) 
     let storyboard = UIStoryboard(name: "Main", bundle: nil) 
     let initialViewController = storyboard.instantiateViewController(withIdentifier: "sw") 
     self.window?.rootViewController = initialViewController 
     self.window?.makeKeyAndVisible() 
    } else if shortcutItem.type == "com.amansk.hardware" { 
     self.window = UIWindow(frame: UIScreen.main.bounds) 
     let storyboard = UIStoryboard(name: "Main", bundle: nil) 
     let initialViewController = storyboard.instantiateViewController(withIdentifier: "hw") 
     self.window?.rootViewController = initialViewController 
     self.window?.makeKeyAndVisible() 
    } 

}

sein sollte