Skip to content

SecItemCopy and SecItemAdd errors #45

Description

@RajivRamaiah

Below is a sample code snippet from my program. I originally was trying to store an NSArray in keychain but when I retrieved it it would no longer be an array of GLAAccount *objects, but an array of strings, so I could not access the property on the objects in the array. Now I encode the object's properties into a string and then decode it after I pull it from the keychain using class methods for the object class, in this case GLAAccount. Occasionally, when I pass data to the view controller the below code is in, the saveAccess method is run and I get a secAddItem error and if I load the data from keychain I get a secCopyItemError. I have set the accessibility as
kSecAttrAccessibleWhenUnlocked. Any thoughts?

//save data from self.accounts in keychain
- (void)saveAccess{
    //clean up the stringArray
    [self.stringArray removeAllObjects];

    //encode every account into a string and add it to string array
    for(GLAAccount *account in self.accounts){
        NSString *string = [GLAAccount encodeAccountObject:account];
        [self.stringArray addObject:string];
    }

    //save string array into keychain
    NSString *key = [NSString stringWithFormat:@"%@accounts", self.currentUser.username];
    [Lockbox setArray:self.stringArray forKey:key accessibility:kSecAttrAccessibleWhenUnlocked];
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions