我基本上跟着this tutorial,很快意识到项目无法编译,因为我使用的是ARC。我设法使用__bridge
(>。>)来阻止所有错误,但我仍然收到一条错误消息,我设法阅读this stack question,但不明白如何应用解决方案我的问题。
基本上给我问题的方法如下:
+ (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;
}
答案 0 :(得分: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];
}