Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Kevin Zoltany
Kevin Zoltany
16,282 Points

Having issues with changing viewcontrollers after Touch ID Succeeds

I'm having an issue with changing view controllers in local authentication. When all the code executes in the success if statement the view controller does not change even though I'm telling it to. I've tried everything that I know but nothing works. Here is my local authentication code.

  let authentication = LAContext()
  var authenticationError: NSError?

  authentication.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &authenticationError)

  if (authenticationError != nil) {
    // Authentication Not available for this version of iOS
    self.gotoMainViewController()
  } else {
    authentication.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "Access Application using Touch ID") {
      (success, error) in
      if (error != nil) {
        // There was an error - user likley pressed cancel
        print(error?.localizedDescription)
      } else {
        if (success) {
          dispatch_async(dispatch_get_main_queue()) {
            self.gotoMainViewController()
          }
        } else {
          self.showFailedTouchIDError.showAlert()
        }
      }
    }
  }

Here is the gotoMainViewController() code.

  func gotoMainViewController() {
   let viewController = MainViewController()
   self.navigationController?.pushViewController(viewController, animated: true)
  }

1 Answer

Michael Reining
Michael Reining
10,101 Points

Hi Kevin,

Have you tried to use a different method to instantiate your view controller?

What about this:

func gotoMainViewController() {

    if let mainVC = storyboard?.instantiateViewControllerWithIdentifier("mainVC") {

        dispatch_async(dispatch_get_main_queue()) { () -> Void in

            navigationController?.pushViewController(mainVC, animated: true)

        }

    }

}

Hope that helps,

Mike

PS: Thanks to the awesome resources on Team Treehouse, I just launched my first app. :-)

Code! Learn how to program with Swift

Kevin Zoltany
Kevin Zoltany
16,282 Points

Sorry to say this, but i don't use interface builder, so the method that you suggested will unfortunately not work for me.