Search code examples
iosswift3dtouch

Check if ViewController was opened with a QuickAction


how can I check if my Swift App was opened with a QuickAction? I search for a solution which can be inside of viewDidLoad.

e.g.

override func viewDidLoad() {
      if *VC was opened with a QuickAction* == true {
          // do this
       else {
          // do sth else
       }
}

Thanks for your help!


Solution

  • When the application is opened through 3D touch following method in AppDelegate is called

    func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
    
    //Navigate to required viewController from here
    //YourViewController.isOpenedThrough3DTouch = true
    }
    

    You can create a base class for all your ViewControllers and declare a bool variable isOpenedThrough3DTouch

    Set this variable to true inside the AppDelegate Callback where the navigation to required ViewController is initiated, So your viewDidLoad knows