我正在尝试使用下面的代码将一些数组数据写入我的钥匙串
// 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);
如您所见,我正在将我的 NSArray 转换为 NSData 然后尝试将 NSData 存储到 kSecAttrGeneric 但是当我尝试 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...
任何帮助将不胜感激。