gpt4 book ai didi

ios - 在 KeyChainItemWrapper 中保存密码时崩溃

转载 作者:技术小花猫 更新时间:2023-10-29 10:15:53 28 4
gpt4 key购买 nike

Apple 在其 GenericKeyChain sample code 中提供了 KeyChainItemWrapper 类. SO 上有一个 ARC'ed 解决方案,我正在尝试遵循:wrapper存储在 iOS 上的 KeyChain 中。

包装器的用法是这样的:

KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"F11-email-auth" accessGroup:nil];
[keychain setObject:[emailTextfield text] forKey:(__bridge id)(kSecMatchEmailAddressIfPresent)];
[keychain setObject:[passwordTextfield text] forKey:(__bridge id)(kSecClassGenericPassword)];

接受带有电子邮件文本字段的行。但是带有密码的第二行崩溃并出现以下异常。

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'
*** First throw call stack:
(
0 CoreFoundation 0x01b445e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018c78b6 objc_exception_throw + 44
2 CoreFoundation 0x01b44448 +[NSException raise:format:arguments:] + 136
3 Foundation 0x014a823e -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 Feeltracker 0x000053b3 -[KeychainItemWrapper writeToKeychain] + 899
5 Feeltracker 0x00004700 -[KeychainItemWrapper setObject:forKey:] + 272
6 Feeltracker 0x000092d6 -[FTLoginViewController connectToAccount:] + 374
7 libobjc.A.dylib 0x018d9874 -

可能是什么原因?我想知道它是否与我使用的常量有关。

更新:

感谢rmaddy的帮助:

这是似乎引发错误的位:

// No previous item found; add the new one.
result = SecItemAdd((__bridge CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL);
NSAssert( result == noErr, @"Couldn't add the Keychain Item." );

结果为 -50。 SecItemAdd 是一个库方法。正如我所料,这在某种程度上与 KeyChain 直接处理有关...

keychainItemData 包含: enter image description here

最佳答案

我再也无法使用这个 Apple 钥匙串(keychain)包装器示例了。幸运的是,对此事的进一步研究揭示了这一点 solution ,这对我有用。

请注意,解决方案的原始答案并未经过 ARC 处理,但是有人非常友好地创建了一个 ARC'ed version on Github .我用了那个,效果很好。

它是 key 链的包装器,比原来的更简单。

希望这能帮助其他有类似问题的人。

关于ios - 在 KeyChainItemWrapper 中保存密码时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19749160/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com