I am trying to write some array data to my keychain using the code below
// set up keychain so I can write to it... or read if needed (specially for testing) KeychainItemWrapper* keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"KeyKeychain" accessGroup:nil]; // write NSData *dataarr = [NSKeyedArchiver archivedDataWithRootObject:parsedRemoteSitesMutableArray]; [keychain setObject:dataarr forKey:(__bridge id)(kSecAttrGeneric)]; // read NSData *myArr = [keychain objectForKey:(__bridge id)(kSecAttrGeneric)]; NSArray *arrayCopy = [NSKeyedUnarchiver unarchiveObjectWithData:myArr]; // log NSLog(@"%@", arrayCopy);
as you can see, I convert my NSArray to NSData and then try to save NSData to kSecAttrGeneric, however I return this error below when I tri for setObject: forKey
Assertion failure in -[KeychainItemWrapper writeToKeychain], /Users/imac/Documents/Iphone applications/appname/appname/KeychainItemWrapper.m:268 2013-07-22 13:54:39.952 key[2167:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.' *** First throw call stack:etc...
Any help would be greatly appreciated.
source share