2017-04-17 87 views
0

我使用以下邏輯來檢查touchID在iPhone上是否可用,並根據返回的值指示用戶註冊touchID或導航它們以設置PIN。它可以在快樂路徑中正常工作,但是如果我已經註冊了一個指紋,但是從iPhone系統設置中禁用了touchID選項,那麼它仍會返回true並導航用戶以設置touchID。如果我刪除所有指紋,則它會按預期方式返回false並導航到PIN屏幕。如何檢查Touch ID是否已註冊但在iPhone上已禁用?

- (BOOL) isTouchIDAvailable { 

    LAContext *myContext = [[LAContext alloc] init]; 
    NSError *authError = nil; 

    if (![myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) { 

     NSLog(@"Touch ID checking error: %@", [authError localizedDescription]); 
     return NO; 
    } 
    return YES; 
} 

我已經提到的關於棧和蘋果開發了一些問題docs

不知道我缺少的是什麼?感謝任何幫助。在此先感謝:)

回答

0

這是不可能的。如果你有TouchID,你有touchID。但是如果你想要的話,你可以用編程方式禁用。查看下面的代碼片段來檢查touchID是否有效。

LAContext *myContext = [[LAContext alloc] init]; 
    NSError *authError = nil; 
    NSString *myLocalizedReasonString = [NSString stringWithFormat:@"Login With your fingerprint with : %@",username]; 

if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) { 
    [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics 
       localizedReason:myLocalizedReasonString 
         reply:^(BOOL success, NSError *error) { 
          if (success) { 
           dispatch_async(dispatch_get_main_queue(), ^{ 
            // [self performSegueWithIdentifier:@"Success" sender:nil]; 
            [self loginWithFingerprint]; 
           }); 
          } else { 
           dispatch_async(dispatch_get_main_queue(), ^{ 
            /* 
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" 
                         message:error.description 
                         delegate:self 
                       cancelButtonTitle:@"OK" 
                       otherButtonTitles:nil, nil]; 
            [alertView show]; 
            */ 
            // Rather than show a UIAlert here, use the error to determine if you should push to a keypad for PIN entry. 
           }); 
          } 
         }]; 
} else { 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     /* 
     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" 
                  message:authError.description 
                  delegate:self 
                cancelButtonTitle:@"OK" 
                otherButtonTitles:nil, nil]; 
     [alertView show]; 
     */ 
     // Rather than show a UIAlert here, use the error to determine if you should push to a keypad for PIN entry. 
    }); 
} 
相關問題