-5

我无法让 KeychainItemWrapper(Apple 示例)工作。我已将 KeychainItemWrapper 文件添加到我的项目中,当在手机上运行它时,SecItemAdd 抛出异常,说一个或多个参数无效(结果代码 -50)。触发 SecItemAdd 的代码如下:

KeychainItemWrapper* wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"something" accessGroup:nil];
[wrapper setObject:@"this is my password" forKey:@"password"];
NSLog(@"Password: %@", [wrapper objectForKey:@"password"]);

怎么了?

代码可以在http://developer.apple.com/iphone/library/samplecode/GenericKeychain/index.html找到

4

1 回答 1

9

我遇到了同样的问题。您不能将任意键放入字典中,您需要使用 SecItemAdd 理解的明确定义的键。

尝试这个:

KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"password" accessGroup:nil];
[wrapper setObject:@"this is my password" forKey:(id)kSecValueData];
NSLog(@"password: [%@]", [wrapper objectForKey:(id)kSecValueData]);
[wrapper release];
于 2010-03-10T22:36:53.267 回答