2014-10-16 9 views
7

मैंने दिशानिर्देशों का पालन किया है और ऐप्पल दस्तावेज से टच आईडी एपीआई के लिए भी उदाहरण दिया है। मैंने अपने अनुप्रयोगों में उदाहरण का उपयोग किया है। मैं टच आईडी का उपयोग करके लॉगिन करने में सक्षम हो सकता था। लेकिन समस्या यह है कि इसका उत्तरदायी बहुत धीमा है। टच आईडी पर अपनी उंगली डालने के बाद, कम से कम 10 सेकंड मुझे सफलता/विफलता की पुष्टि करने के लिए इंतजार करना होगा। मैंने ऐप प्रतिनिधि फ़ाइल में कोड का उपयोग किया है। मैंने विभिन्न ऐप्स के साथ भी परीक्षण किया है लेकिन परिणाम वही "देरी प्रतिक्रिया" है। दोस्तों कृपया इस मामले में मेरी मदद करें।टच आईडी एपीआई उत्तरदायी बहुत धीमा है

+0

क्या मुझे प्रेषण कतार में कोड लिखना चाहिए? – user4150758

+0

मैंने यह भी देखा है। मैंने ऐप्पल के उदाहरण का पालन किया और मुझे कॉलबैक मिलने से पहले काफी सेकंड लग रहा है। उम्मीद है कि किसी के पास कुछ जवाब हैं क्योंकि इस पर ऐप्पल का दस्तावेज कमजोर है। – Inertiatic

+0

हाँ। लेकिन मुझे यकीन नहीं है कि 1password कैसे बेकार है। – user4150758

उत्तर

22
LAContext *myContext = [[LAContext alloc] init]; 

NSError *authError = nil; 

NSString *myLocalizedReasonString = <#String explaining why app needs authentication#>; 

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

    [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics 
       localizedReason:myLocalizedReasonString 
         reply:^(BOOL success, NSError *error) { 

          if (success) { 
            // User authenticated successfully, take appropriate action 
            dispatch_async(dispatch_get_main_queue(), ^{ 
              // write all your code here 
           }); 
          } else { 
            // User did not authenticate successfully, look at error and take appropriate action 

           switch (error.code) { 
            case LAErrorAuthenticationFailed: 
             NSLog(@"Authentication Failed"); 
             break; 

            case LAErrorUserCancel: 
             NSLog(@"User pressed Cancel button"); 
             break; 

            case LAErrorUserFallback: 
             NSLog(@"User pressed \"Enter Password\""); 
             break; 

            default: 
             NSLog(@"Touch ID is not configured"); 
             break; 
           } 

           NSLog(@"Authentication Fails"); 
          } 
         }]; 
} else { 
    // Could not evaluate policy; look at authError and present an appropriate message to user 
} 
+0

@vishal ... धन्यवाद। यह बेकार ढंग से काम किया :) – user4150758

+0

@ user4150758 आपका स्वागत है .. !! –

+0

कोई भी बता सकता है कि ब्लॉक निष्पादन के बाद धागा क्या करता है? – Rainelz

6

आप} else

dispatch_async(dispatch_get_main_queue(), ^{ 
//update ui 
}); 

LAContext *context = [[LAContext alloc] init]; 

NSError *error = nil; 

if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { 
// Authenticate User 

NSError *error = nil; 
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { 
    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics 
      localizedReason:@"Please verify that you are the device owner in order to place the order" 
        reply:^(BOOL success, NSError *error) { 
         dispatch_async(dispatch_get_main_queue(), ^{ 
         if (error) { 
          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                      message:@"There was a problem verifying your identity." 
                     delegate:nil 
                   cancelButtonTitle:@"Ok" 
                   otherButtonTitles:nil]; 
          [alert show]; 
          return; 
         } 

         if (success) { 
          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                      message:@"You are the device owner!" 
                     delegate:nil 
                   cancelButtonTitle:@"Ok" 
                   otherButtonTitles:nil]; 
          [alert show]; 

         } else { 
          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                      message:@"You are not the device owner." 
                     delegate:nil 
                   cancelButtonTitle:@"Ok" 
                   otherButtonTitles:nil]; 
          [alert show]; 
         } 
         }); 
        }]; 
} 

साथ मुख्य थ्रेड में alertviews प्रदर्शित करने के लिए {

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

}

1

के रूप में अन्य ने कहा, आप यूआई बात क्या करना है मुख्य धागे पर, स्विफ्ट 3.0 के लिए यह है:

myContext.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: myLocalizedReasonString) { (success, evaluateError) in 
      DispatchQueue.main.async { 
        if (success) { 
         //success 
        } else { 
         //failure 
        } 
       } 
      } 
संबंधित मुद्दे