title: Appdelegate problems
body: <p>I'm having problems opening my app from a link through Safari (later it will be from my own app)
  If the app is open, there are no problems. If the app is not open, it crashes, when opening through a URL. I've learned that It is because I call 2 different methods in Appdelegate -  <code>didFinishLaunchingWithOptions</code> and <code>open url</code></p>
  
  <p>I have no problems opening through open url when the app is open, but the app crashes if I am opening through url on closed app. I've learned that my url parameter in <code>didFinishLauchingWithOptions</code> is probably null, but how do you test it. When I close the app on both simulator and iPad XCode terminates the connection</p>
  
  <p><strong>EDIT</strong> - Now able to debug, after Sachin Vas' comment. 
  Getting this in XCode debug - but can't expand the payload <a href="https://i.stack.imgur.com/XVeJ8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XVeJ8.png" alt="enter image description here"></a></p>
  
  <p>My functions look like this</p>
  
  <pre><code>func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -&gt; Bool {
      self.window = UIWindow(frame: UIScreen.main.bounds)
      let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
  
      let nav = storyBoard.instantiateViewController(withIdentifier: "HomeNavController") as! UINavigationController
      let home = storyBoard.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
  
  
  
      if let url = launchOptions?[UIApplicationLaunchOptionsKey.url] as? NSURL {
          if let itemid = getQueryStringParameter(url: url.absoluteString!, param: "itemid"){
              NetworkService().getSpecificExercise(id: itemid) { response, error in
                  let exercise = response! as VoiceExercise
                  let vc = storyBoard.instantiateViewController(withIdentifier: "ExerciseViewController") as! ExerciseViewController
                  vc.exercise = exercise
                  switch exercise.type {
                  case "STRENGTH":
                      vc.exercisetype = .strength
                  case "RANGE":
                      vc.exercisetype = .range
                  case "COMBINED":
                      vc.exercisetype = .combined
                  default:
                      print(exercise.type)
                  }
                  nav.pushViewController(vc, animated: false)
                  self.window?.rootViewController = nav
                  //self.window?.makeKeyAndVisible()
  
              }
              return true
          }
      }else{
          //nav.pushViewController(home, animated: true)
          self.window?.rootViewController = home
          self.window?.makeKeyAndVisible()
      }
  
      nav.pushViewController(home, animated: true)
      self.window?.rootViewController = nav
      self.window?.makeKeyAndVisible()
      return true
  }
  
  func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -&gt; Bool {
      if let itemid = getQueryStringParameter(url: url.absoluteString, param: "itemid"){
          NetworkService().getSpecificExercise(id: itemid) { response, error in
              let exercise = response! as VoiceExercise
              let vc = storyBoard.instantiateViewController(withIdentifier: "ExerciseViewController") as! ExerciseViewController
              vc.exercise = exercise
              switch exercise.type {
              case "STRENGTH":
                  vc.exercisetype = .strength
              case "RANGE":
                  vc.exercisetype = .range
              case "COMBINED":
                  vc.exercisetype = .combined
              default:
                  print(exercise.type)
              }
              self.window?.rootViewController = vc
              self.window?.makeKeyAndVisible()
  
          }
          return true
      }else{
          return false
      }
  
  }
  </code></pre>