2012-08-23 13 views
6

Sto utilizzando la classe KeychainItemWrapper (file .h e .m integrato nel progetto) per il salvataggio del passcode in Keychain per l'app iOS. Anche importato "Security" Framework e la classe "keychianItemWrapper.h" nel progetto dovunque sia necessario. (# Import, #import "KeychainItemWrapper.h")Restituisce "0" ogni volta quando recupera il portachiavi salvato il passcode dall'accesso portachiavi per l'app ios

Sto utilizzando il codice riportato di seguito nel metodo delegato dell'app per il salvataggio del passcode in accesso portachiavi:

if([textfieldPassword1.text isEqual:textfieldPassword2.text]){ 

       NSLog(@"CONGRATS !! PASSCODE MATCHED !!!");   

       //converting "textfieldPassword1" to NSNumber 
       NSNumber *textfieldPasscode1Num = [NSNumber numberWithInt:[textfieldPassword1.text intValue]]; 

       //saving passcode to the keychain access 
       [keychain setObject:textfieldPasscode1Num forKey:(__bridge id)kSecValueData]; 

      // [keychain setObject:[NSNumber numberWithInt:[textfieldPassword1.text intValue]] forKey:(__bridge id)kSecAttrAccount]; 

       // if passcode matches then load Show Lock Screen Page 
       self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
       self.viewController = [[ViewController alloc] init]; 
       [self.window addSubview:self.viewController.view]; 
       [self.window makeKeyAndVisible]; 
      } 

E Eccomi REIMPOSTAZIONE codice di accesso utilizzando sottostante Codice:

if(_isResetPasscode){ 
       NSLog(@"Code here for Update Passcode in Keychain Access !!!"); 
       _isResetPasscode = FALSE; 

       // "keychain" is object of "KeychainItemWrapper" class   
       [keychain resetKeychainItem]; 

/* Again setting the new passcode entered by user in keychain access.. IT IS NOT SAVING IN keychain access, where above the same line of code was working for saving passcode in keychain access 
/* 
       [keychain setObject:resetPasscodeNum forKey:(__bridge id)kSecValueData]; 

       NSLog(@"----Passcode Re-Setted ----!! %@\n",resetPasscodeNum); 
      } 

Quando sto stampando portachiavi codice di accesso in console ogni volta che la fase di stampa "0". Per favore guidami dove sto sbagliando ... Il tuo aiuto sarebbe apprezzato !!

Grazie in anticipo

risposta

0

Non è stato specificato il formato della password immessa. Suppongo che potrebbe essere qualsiasi tipo di testo. Se questo è il caso, questa riga fallirà se il testo inserito non è effettivamente un numero:

[textfieldPassword1.text intValue] 

e restituirà 0;

+0

Hi codice di accesso @Gambit immesso è "Numero" di ingresso, vedi codice sto usando "UIKeyboardTypeNumberPad" per il codice di accesso: UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: @ "Enter Passcode" un messaggio: @ "Inserire Codice a 4 cifre "delegato: self cancelButtonTitle: @" OK "otherButtonTitles: @" Annulla ", nil]; textfieldPassword1 = [[UITextField alloc] initWithFrame: CGRectMake (12.0, 90.0, 260.0, 25.0)]; textfieldPassword1.keyboardType = UIKeyboardTypeNumberPad; [textfieldPassword1 setDelegate: self]; [alertView addSubview: textfieldPassword1]; [show Mostra avviso]; – NSExpression

Problemi correlati