出于某种原因,在 OSX 10.8.4 上调用 SecItemCopyMatching 时,我得到了一个空字典。对应的项目在钥匙串中,包含用户名和密码。SecItemCopyMatching 找到它(errSecSuccess),但结果字典只包含 0 个条目。我希望它至少有用户名和密码数据,那么我的请求有什么问题?
OSStatus status;
NSMutableDictionary *query = [NSMutableDictionary dictionary];
[query setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
[query setObject:(id)kSecReturnAttributes forKey:(id)kCFBooleanTrue];
[query setObject:@"MyService" forKey:(id)kSecAttrService];
CFDictionaryRef dictRef = NULL;
status = SecItemCopyMatching((__bridge CFDictionaryRef)query, (CFTypeRef *)&dictRef);
if (status != errSecSuccess) {
CFStringRef errorRef = SecCopyErrorMessageString(status, NULL);
NSLog(@"%s: %@", __FUNCTION__, (__bridge NSString *)errorRef);
CFRelease(errorRef);
return nil;
}
// --> dictRef empty
if (dictRef != NULL) CFRelease(dictRef);