开发者

iPhone Keychain

I can't get the KeychainItemWrapper (Apple example) to work. I've added the KeychainItemWrapper files to my project and when running it on the phone, an exception is thrown by SecItemAdd, saying that one or more parameters were not valid (result code -50). The code triggering the SecItemAdd follows:

KeychainItemWrapper* wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"something" accessGroup:nil];
[wr开发者_如何学JAVAapper setObject:@"this is my password" forKey:@"password"];
NSLog(@"Password: %@", [wrapper objectForKey:@"password"]);

What is wrong?

The code can be found at http://developer.apple.com/iphone/library/samplecode/GenericKeychain/index.html


I ran into this same issue. You can't put arbitrary keys in the dictionary, you need to use well-defined keys that the SecItemAdd understands.

Try this:

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜