获取Keychain的属性将返回NSArray

时间:2016-08-30 08:08:38

标签: ios objective-c iphone keychain

我想获得一个Keychain属性字典,但我得到一个NSArray,其中包含1个NSDictionary元素。这是获取属性的代码:

NSMutableDictionary *queryDictionary = [KeychainQueryDictionaryWithServiceAndIdentifier(serviceName, identifier) mutableCopy];
queryDictionary[(__bridge id)kSecReturnAttributes] = (__bridge id)kCFBooleanTrue;
queryDictionary[(__bridge id)kSecMatchLimit] = (__bridge id)kSecMatchLimitAll;

CFDictionaryRef result = nil;
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)queryDictionary, (CFTypeRef *)&result);

if (status != errSecSuccess) {
    NSLog(@"Unable to fetch account info with identifier \"%@\" (Error %li)", identifier, (long int)status);
    return nil;
}

id ret = (NSDictionary *)CFBridgingRelease(result);

这是来自控制台的一些信息

enter image description here

为什么retNSArray类型?

1 个答案:

答案 0 :(得分:0)

queryDictionary[(__bridge id)kSecMatchLimit] = (__bridge id)kSecMatchLimitOne;

修正了它!