2017-02-03 5 views
2

タッチID inmy iOSアプリを有効にしました。しかしiPhone 5と5cでは、指紋センサーは利用できません。指紋センサーを持たないデバイスをプログラムで検出するにはどうすればよいですか?私のアプリは対物レンズで書かれています。フィンガープリントセンサーが検出できないデバイス

私を助けてください。 ありがとう

+0

http://stackoverflow.com/questions/11197509/ios-how-to-get -device-make-and-model。これを使用して、デバイスのモデルを探します。 –

答えて

1

Touch ID認証に必要なLAContextフレームワークを使用する必要があります。

LAErrorTouchIDNotAvailableは、どのデバイスに機能があるかを示します。

コードスニペット:

- (IBAction)shouldAuthenticate:(id)sender { 
    LAContext *context = [[LAContext alloc] init]; 
    NSError *error = nil; 

    if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { 
    // Authentication here. 
    } else { 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                message:@"Your device cannot authenticate using TouchID." 
                delegate:nil 
              cancelButtonTitle:@"Ok" 
              otherButtonTitles:nil]; 
    [alert show]; 

    } 
}  

またはBOOLのリターンを得るために、この方法を試してください。

- (BOOL)canAuthenticateByTouchId { 
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) { 
    return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]; 
    } 
    return NO; 
} 
+1

ありがとうございます。デバイスにタッチIDセンサーがあり、ユーザーがタッチIDを設定していない場合はどうなりますか?私には何のエラーメッセージも出ません。これをどのように検出できますか? – user1960169

+1

https://the-nerd.be/2015/10/01/authentication-with-touchid/ Touch IDの設定はこれを非常に簡単にチェックしてください。 あなたが私の答えが好きなら、投票してください。 ありがとう –

+0

Gr8の仕事@AnkitKumarGupta –

0
func checkIfTouchIDEnabled() { 

var error:NSError? 

// 2. Check if the device has a fingerprint sensor 
// If not, show the user an alert view and bail out! 
guard authenticationContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else { 

    if let error = error as NSError? { 

     if error.code == LAError.Code.touchIDNotAvailable.rawValue { /* Device does not support touch id*/ 

     print("Finger print sensors are not present in this device") 

     } else if error.code == LAError.Code.touchIDNotEnrolled.rawValue { 
     print("Finger print sensors are present in this device but no TouchID has been enrolled yet") 
     } else { 
     // Add more checks ... 
     } 
    } 
    return 
} 
} 
+0

このコードが何を行うのか、これがテキストセクションのQからどのように問題を解決するのかを説明してください。 – loki

+0

私は指紋センサーが存在するかどうかを確認する方法を尋ねていたと思います。私は、現在の指紋センサと指紋センサを区別したいと思っていますが、指紋は追加されていません。 –

+0

答えに説明文を入力してください(https://stackoverflow.com/posts/46169804/edit)。したがって、将来のユーザーはあなたのアプローチに従って理解することができます。 – loki

関連する問題