2017-11-07 5 views
0

の承認後にSegueを実行する方法タッチID で承認した後で初めて、ユーザがログイン後にSegueを使用して2番目のViewControllerに転送したい場合があるかもしれませんが、ボタンにあります。タッチID

import UIKit 
import LocalAuthentication 

class LoginWindowViewController: UIViewController { 


    @IBAction func loginButton(_ sender: Any) { 

     let context: LAContext = LAContext() 
     if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil){ 

      context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "For login you need to use your TouchID", reply: {(wasSuccessful, error) in if wasSuccessful { 
       DispatchQueue.main.async { 
    self.shouldPerformSegue(withIdentifier: "LoginComplete", sender: self.navigationController) 
       } 
      }else{ 
       print ("Bad TouchID") 
       } 


      }) 

     } 


    } 

おかげ

答えて

0

この機能を実装し、それが呼ばれていた場所からチェックしてみてください。

override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { 

} 

すでにを追加した場合、あなたのコードからセグエを呼び出しているとことを覚えておいてくださいあなたのボタンからストーリーボード内の次のViewControllerへのsegueアクションを削除する必要があります。呼び出したいものへのLoginViewControllerとの接続を作成します。

+0

これは良いアドバイスであり、ソリューションのおかげです。 – Ula

+0

あなたはこの問題をどのように解決したか教えていただけますか? –

+1

問題は正しくないsegueであった、segueはボタンから2番目のViewControllerに行かなくてはならないが、最初のViewControllerから別のViewControllerにしか移動しない。エラー!?_コード ケースLAError.Code.userCancel.rawValue: self.alertUser( "Please try again again"エラー:.localizedDescription) デフォルト:self.alertUser( "認証に失敗しました"、 エラー:エラー? .localizedDescription) } } else {self.performSegue(withIdentifier: "LoginSuccess"、送信者:self.navigationController) } – Ula

0

documentationのように、shouldPerformSegueメソッドをオーバーライドしないと、デフォルト実装はすべてのセグに対してtrueを返します。

shouldPerformSegue(withIdentifier:sender:)メソッドは、実装の戻り値に応じて、指定された識別子のセグが呼び出されるかどうかを判断する必要があります。

TouchIDの承認が成功したかどうかを確認しているので、実際にshouldPerformSegueに電話する必要はなく、performSegueに電話する必要があります。

context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "For login you need to use your TouchID", reply: {(wasSuccessful, error) in 
    if wasSuccessful { 
     DispatchQueue.main.async { 
      self.performSegue(withIdentifier: "LoginComplete", sender: self.navigationController) 
     } 
    }else{ 
     print ("Bad TouchID") 
    } 
})