使用 KeychainItemWrapper iPhone SDK 时收到 SIGABRT
我正在编写一个应用程序,它使用“KeychainItemWrapper”类以安全的方式存储登录凭据。这是管理钥匙串对象的代码:
- (IBAction)saveFields {
wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"username" accessGroup:nil];
[wrapper setObject:[self.password text] forKey:(id)kSecAttrAccount];
[wrapper release];
wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"password" accessGroup:nil];
[wrapper setObject:[self.password text] forKey:(id)kSecAttrAccount];
[wrapper release];
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)isUserLogged {
wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"username" accessGroup:nil];
if ( [[wrapper objectForKey:(id)kSecAttrAccount] isEqualToString:@""] ) {
return NO;
} else {
username = [NSString stringWithString:[wrapper objectForKey:(id)kSecAttrAccount]];
[wrapper release];
}
wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"password" accessGroup:nil];
if ( [[wrapper objectForKey:(id)kSecAttrAccount] isEqualToString:@""] ) {
return NO;
} else {
password = [NSString stringWithString:[wrapper objectForKey:(id)kSecValueData]];
[wrapper release];
}
return YES;
}
当我尝试在钥匙串中写入凭据时,我收到 SIGABRT 错误,如下所示:
// KeychainItemWrapper.m
// - (void)writeToKeychain;
result = SecItemAdd( (CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL );
I'm writing an application that uses the class "KeychainItemWrapper" for storing in a secure way login credentials. Here's the code that manages the Keychain object:
- (IBAction)saveFields {
wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"username" accessGroup:nil];
[wrapper setObject:[self.password text] forKey:(id)kSecAttrAccount];
[wrapper release];
wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"password" accessGroup:nil];
[wrapper setObject:[self.password text] forKey:(id)kSecAttrAccount];
[wrapper release];
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)isUserLogged {
wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"username" accessGroup:nil];
if ( [[wrapper objectForKey:(id)kSecAttrAccount] isEqualToString:@""] ) {
return NO;
} else {
username = [NSString stringWithString:[wrapper objectForKey:(id)kSecAttrAccount]];
[wrapper release];
}
wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"password" accessGroup:nil];
if ( [[wrapper objectForKey:(id)kSecAttrAccount] isEqualToString:@""] ) {
return NO;
} else {
password = [NSString stringWithString:[wrapper objectForKey:(id)kSecValueData]];
[wrapper release];
}
return YES;
}
I receive the SIGABRT error when I try to write credentials in the keychain, here:
// KeychainItemWrapper.m
// - (void)writeToKeychain;
result = SecItemAdd( (CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然,故障出在 NSAssert() 块上。评论该行解决了问题。
Apparently, the fault was on the NSAssert() block. Commenting the line solved the problem.