ios - OSStatus 错误代码 -34018

标签 ios objective-c ios9 keychain

我正在使用 SecItemCopyMatching 来访问 iOS 钥匙串(keychain)。从后台重新启动应用程序后,我大约有一百分之一得到 -34018 结果代码。 The documentation状态:

The assigned error space for Keychain Services is discontinuous: –25240 through –25279 and –25290 through –25329. Keychain Item Services may also return noErr (0) or paramErr (–50), or CSSM result codes

所以看来 -34018 是一个'CSSM结果代码'。我关注了suggested link但找不到结果代码。

-34018 结果码是什么?如何获得更可靠的钥匙串(keychain)访问?

- (NSData *)getKeychainData:(NSString *)key
{
    NSDictionary *query = @{
        (__bridge id)kSecClass:(__bridge id)kSecClassGenericPassword,
        (__bridge id)kSecAttrService:SEC_ATTR_SERVICE,
        (__bridge id)kSecAttrAccount:key,
        (__bridge id)kSecReturnData:@YES
    };

    CFDataRef result = nil;

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

    if(status == errSecItemNotFound) {
        return nil;
    }

    if(status == noErr) {
        return CFBridgingRelease(result);
    } else {
        [self logError:[NSString stringWithFormat:@"SecItemCopyMatching status %d", (int)status] :nil];
        return nil;
    }
}

最佳答案

经过一番研究,我发现:http://opensource.apple.com/source/Security/Security-55471/sec/Security/SecBasePriv.h

所以 -34018errSecMissingEntitlement 并且评论说

Internal error when a required entitlement isn't present.

您在运行单元测试时是否遇到此错误?如果是这样,这可能会有所帮助:https://stackoverflow.com/a/22305193/171933

github 上的这个问题说它似乎只在从 Xcode 调试时发生:https://github.com/soffes/sskeychain/issues/97 (另见 https://stackoverflow.com/a/28256591/171933)

希望这会有所帮助!

关于ios - OSStatus 错误代码 -34018,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29740952/

相关文章:

iphone - 允许对象类型为 'id' 还是为方法的两种不同类型提供两个参数更好?

ios - 有没有办法在注释 View 层中设置 z-order?

iphone - iOS 无法旋转

ios - 使用 ReactiveCocoa 每小时执行一次操作

http - 具有 http 域的 api 在 xcode 7.1 中不起作用

ios - 验证 podspec 时出错

ios - 快速错误 : Argument labels '(_:)' do not match any available overloads

objective-c - 如何设置 NSTableCellView 的背景颜色?

ios - EXC_BAD_ACCESS 尝试返回 uint64_t 数字时

swift - iOS 9、Xcode 7、带 SpriteKit 的多点触控