keychain is not remembering information when testing on device

Discussion in 'iPhone' started by johnmerlino, Feb 28, 2013.

  1. johnmerlino macrumors member

    Oct 22, 2011
    While testing device, I expect when I clicking run if I loaded information in keychain already, then it should exist when I run it again. However, the username and pass stored in keychain does not exist on a second run. Maybe because its instantiating a new instance of keychain during each viewDidLoad, but then how else would I get the existing keychain information?

     - (void)viewDidLoad
        [super viewDidLoad];
        keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"XKRemoteiPhone" accessGroup:nil];
    - (IBAction)performLogin:(id)sender { 
        NSString* username;
        NSString* password;
        if (![[keychain objectForKey:(__bridge id)kSecAttrAccount] length] || ![[keychain objectForKey:(__bridge id)kSecValueData] length]){
            username = self.emailField.text;
            password = self.passwordField.text;
            [keychain setObject:self.emailField.text forKey:(__bridge id)kSecAttrAccount];
            [keychain setObject:self.passwordField.text forKey:(__bridge id)kSecValueData];
        else {
            username = [keychain objectForKey:(__bridge id)kSecAttrAccount];        
            password = [keychain objectForKey:(__bridge id)kSecValueData];
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/pages/login.json", RemoteUrl]];
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
        [request addRequestHeader:@"Content-Type" value:@"application/json"];
        [request setRequestMethod:@"POST"];
        [request appendPostData:[[NSString stringWithFormat:@"{\"user\":{\"email\":\"%@\", \"password\":\"%@\"}}", username, password] dataUsingEncoding:NSUTF8StringEncoding] ];
        [request setNumberOfTimesToRetryOnTimeout:5];
        [request setTimeOutSeconds:100];
        [request startSynchronous];
  2. johnmerlino thread starter macrumors member

    Oct 22, 2011
    Turned off iphone and turned it back on and then it works. Another example of poorly designed infrastructure. Thank goodness for android.

Share This Page