我刚刚发现我的应用程序存在一个有趣的问题.在应用程序中,我将用户的用户名和密码保存到钥匙串中.
I just found an interesting problem with my app. In the app I am saving the user's user name and password to the keychain.
keychainWrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"MyLoginPassword" accessGroup:nil];
[keychainWrapper setObject:usernameField.text forKey:(id)kSecAttrAccount];
[keychainWrapper setObject:passwordField.text forKey:(id)kSecValueData];
当这段代码在 Debug 中运行时,它似乎工作得很好.它每次都会更新,我以后可以从钥匙串中检索项目.当它在 Distribution 中运行时,钥匙串永远不会更新.我已经验证是的,这些代码行在两个版本中都被命中.我正在使用带有 iOS5 SDK 的 Xcode 4.2,并在安装了 iOS5 的 iPad 2 上运行该应用程序.
When this code is run in Debug it seems to work just fine. It updates each time and I can later retrieve the items from the keychain. When it is run in Distribution however the keychain never gets updated. I have verified that yes these lines of code are hit in both builds. I am using Xcode 4.2 with the iOS5 SDK and running the app on an iPad 2 with iOS5 installed.
我也遇到了这个问题,想了很久
I also had this problem, and it took me forever to figure out
有一个版本的KeychainWrapper"在 NSAssert 中浮动(除其他外).
There is a version of "KeychainWrapper" floating around that has it's SecItemUpdate within an NSAssert (among other things).
做这件事的人是个白痴!在为发布/分发而构建时,每个 NSAssert 都无效,这意味着代码甚至无法运行.
Whoever did this is a moron!, when building for release/distribution every NSAssert is nullified, meaning that code doesn't even get run.
例如:
NSAssert(SecItemUpdate((CFDictionaryRef)updateItem, (CFDictionaryRef)tempCheck), @"Couldn't update the Keychain Item." );
需要成为
OSStatus status = SecItemUpdate((CFDictionaryRef)updateItem, (CFDictionaryRef)tempCheck);
NSAssert(status == noErr, @"Couldn't update the Keychain Item." );
注意实际的 SecItemUpdate 是如何移动到 NSAssert 之外的,而是检查结果
Notice how the actual SecItemUpdate is moved outside the NSAssert, and instead the result is checked
重要提示:尝试更新 kSecValueData 的值,而不指定 kSecAttrAccount 的值,也会导致断言失败.因此,如果您的意图是存储单个敏感数据字符串(例如信用卡号码列表),请务必在 kSecAttrAccount 属性中存储一些帐户名称"文本,如下所示:
Important note: Attempting to update a value for kSecValueData, without also specifying a value for kSecAttrAccount, will cause the assertion to fail as well. So, if your intent is to store a single string of sensitive data (such as a list of credit card numbers), be sure to store some "account name" text in the kSecAttrAccount attribute, like so:
static NSString* kCardListXML = @"cardListXML";
static NSString* cardListAccountName = @"cardListAccount";
-(void)setCardListXML:(NSString*)xml {
KeychainItemWrapper* wrapper =
[[KeychainItemWrapper alloc] initWithIdentifier:kCardListXML accessGroup:nil];
[wrapper setObject:cardListAccountName forKey:(id)CFBridgingRelease(kSecAttrAccount)];
[wrapper setObject:xml forKey:(id)CFBridgingRelease(kSecValueData)];
}
-(NSString*)getCardListXML {
KeychainItemWrapper* wrapper =
[[KeychainItemWrapper alloc] initWithIdentifier:kCardListXML accessGroup:nil];
[wrapper setObject:cardListAccountName forKey:(id)CFBridgingRelease(kSecAttrAccount)];
return [wrapper objectForKey:CFBridgingRelease(kSecValueData)];
}
这篇关于iOS KeychainItemWrapper 未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!