当我启动我的应用程序时,我想检查钥匙串中是否有任何存储的凭据,所以我正在尝试这个:
- (BOOL)areStoredCredentials {
if(![keychain objectForKey:(id)kSecAttrAccount]) return NO;
else{
NSLog(@"STORED CREDENTIALS : %@ / %@", [keychain objectForKey:(id)kSecAttrAccount], [keychain objectForKey:(id)kSecValueData]);
self.login = [keychain objectForKey:(id)kSecAttrAccount];
self.password = [keychain objectForKey:(id)kSecValueData];
return YES;
}}
但即使存储的凭据为空,此函数也不会返回NO。它甚至打印:
2011-11-13 21:58:07.205 NeroApp [541:f803]存储的证书:/
有人知道为什么吗?
答案 0 :(得分:3)
看起来你正在从钥匙串中获取空字符串。您可以尝试这种检查:
if (![[keychain objectForKey:(id)kSecAttrAccount] length]) return NO;
else {
...
}