1

我基本上按照本教程进行操作,很快就意识到该项目无法编译,因为我使用的是 ARC。我设法使用__bridge(>.>) 抑制了所有错误,但我仍然收到一条错误消息,并且我设法阅读了这个堆栈问题,但不明白如何将解决方案应用于我的问题。

基本上给我问题的方法如下所示:

+ (NSString*)getPasswordForKey:(NSString*)aKey
{
 NSString *password = nil;

 NSMutableDictionary *searchDictionary = [self dictionaryForKey:aKey];

 [searchDictionary setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit];
 [searchDictionary setObject:(id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData];


 NSData *result = nil;
 SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary, (CFTypeRef *)&result);

 if (result)
 {
    password = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];

 }
 return password;
} 
4

1 回答 1

4

我认为您通过尝试转换指针到指针的参数来进行不必要的复杂类型转换。这个怎么样:

CFTypeRef result = NULL;
BOOL statusCode = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary, &result);
if (statusCode == errSecSuccess) {
    NSData *resultData = CFBridgingRelease(result);
    password = [[NSString alloc] initWithData:resultData encoding:NSUTF8StringEncoding];
}
于 2012-06-13T11:28:16.590 回答