LoginSignup
27
25

More than 5 years have passed since last update.

iOS 8で導入されたLocal Authenticationを使ってTouchID認証

Last updated at Posted at 2014-06-07

iOS 8から追加された Local Authentication でTouchID認証を行うドキュメントが 一般にも公開 されていたのでメモ。

Local Authentication Framework Reference

サンプルコード

- (void)authStart
{
    // 認証用のオブジェクト生成
    LAContext *myContext = [[LAContext alloc] init];
    NSError *authError = nil;
    NSString *myLocalizedReasonString = @"認証を行う理由をここに書く";

    // 生体認証(TouchID)の利用が可能か?
    if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError])
    {
        [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                  localizedReason:myLocalizedReasonString
                            reply:^(BOOL success, NSError *error)
         {
             if (success) {
                 // 認証に成功した
             }
             else {
                 // 認証に失敗した
             }
         }];
    }
    else {
        // TouchIDが使用できない(古い端末を使用した場合など)
    }
}

evaluatePolicy には認証ポリシーを指定できますが、現時点では LAPolicyDeviceOwnerAuthenticationWithBiometrics のみ指定可能なようです。

注意点

LocalAuthenticationは実機でのみ動作するようです。シミュレータで実行しようとするとエラーになります。

Xcode 6は現在NDA下にあるため、実行結果のスクリーンショットの掲載は控えておきます。

27
25
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
27
25