LoginSignup
7
7

More than 5 years have passed since last update.

Touch ID: Local Authentication の機能を追加してみる

Posted at

Local Authenticationするゲートの画面を追加

View Controller をRoot画面で追加

追加する

image

リネームする

image

Rootにする

image

ボタン追加とリネーム

image

新Rootから旧Rootにセグエ追加

image

リネーム

image

ボタンのハンドラ追加

追加したボタンをダブクリして、ハンドラ追加してコードをコピペ:


        void AuthenticateMe (UIButton sender) 
        {    
            var context = new LAContext(); 
            NSError AuthError; 
            var myReason = new NSString("To add a new chore"); 

            if (context.CanEvaluatePolicy(
                LAPolicy.DeviceOwnerAuthenticationWithBiometrics, 
                out AuthError)){ 

                var replyHandler = new LAContextReplyHandler((success, error) => 
                    { 
                        this.InvokeOnMainThread(()=>{ 
                            if(success){ 
                                Console.WriteLine("You logged in!"); 
                                PerformSegue("AuthenticationSegue", this); 
                            } else{ 
                                //Show fallback mechanism here 
                            } 
                        }); 
                    }); 
                context.EvaluatePolicy(
                    LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler); 
            }; 
        }

        partial void AuthenticateButton_TouchUpInside (UIButton sender)
        {
            this.AuthenticateMe(sender);
        }

ターゲットOS変更

image

実行

親指だと認証と追ってしまうので、人差し指使ってスクショ取ったために認証エラーになっている。親指だと認証通って、セグエでPushする先のView Controllerに移動します。

image

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7