来自 AppDelegate 的 ViewController

Present a ViewController from the AppDelegate

我在 Info.plist 中设置了 3D Force Touch Action。现在我希望当 3D 动作是 运行 时,它会显示一个视图控制器,我给它一个故事板 ID,我需要在 AppDelegate 中执行此操作。

我使用了performActionForShortCutItem函数。

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    if let tabVC = self.window?.rootViewController as? UITabBarController {
        if shortcutItem.type == "Hausaufgaben" {
            tabVC.selectedIndex = 1
            tabVC.performSegue(withIdentifier: "gotoHausaufgaben", sender: nil)
        }    
    }        
}
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
   if shortcutItem.type == "Hausaufgaben" {
      self.window = UIWindow(frame: UIScreen.main.bounds)
      let storyboard = UIStoryboard(name: "Main", bundle: nil)
      let initialViewController = storyboard.instantiateViewController(withIdentifier: "YOUR PAGE Identifier")
      self.window?.rootViewController = initialViewController
      self.window?.makeKeyAndVisible()
   }
}