使用 KeychainItemWrapper iPhone SDK 时收到 SIGABRT

发布于 2024-10-07 11:43:13 字数 1376 浏览 6 评论 0原文

我正在编写一个应用程序,它使用“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铃予 2024-10-14 11:43:13

显然,故障出在 NSAssert() 块上。评论该行解决了问题。

Apparently, the fault was on the NSAssert() block. Commenting the line solved the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文