我正在尝试使用 KeyChain 并且不使用包装器。但是当我想读取该值时,我的代码崩溃了。
代码:
CFDictionaryRef attributes = CFDictionaryCreate(NULL, keys, values, 5, NULL, NULL);
CFDataRef result;
OSStatus status = SecItemAdd(attributes, (CFTypeRef *)&result);
if (status == errSecSuccess) {
if (result && CFGetTypeID(result) == CFDataGetTypeID()) { //crashes here
NSLog(@"Data");
}
isSuccess = YES;
} else {
fprintf(stderr, "Error while inserting into keychain osstatus:%ld\n", status);
}
错误:EXC_BAD_ACCESS
我做错了什么?我以为SecItemAdd可以返回新添加的item
编辑:
const void *keys[] = {
kSecClass
, kSecAttrAccessible
, kSecAttrService
, kSecAttrAccount
, kSecValueData
};
const void *values[] = {
kSecClassGenericPassword
, kSecAttrAccessibleWhenUnlocked
, (__bridge CFStringRef)service
, (__bridge CFStringRef)account
, data //CFDataRef
};
最佳答案
来自文档:
To obtain the data of the added item as an object of type CFDataRef, specify the return type key kSecReturnData with a value of kCFBooleanTrue.
关于iOS KeyChain secItemAdd 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23696067/