我正在嘗試使用KeyChain並且沒有包裝。但是當我想讀取值時,我的代碼崩潰了。iOS KeyChain secItemAdd crash
代碼:
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可以返回新添加的項
編輯:
const void *keys[] = {
kSecClass
, kSecAttrAccessible
, kSecAttrService
, kSecAttrAccount
, kSecValueData
};
const void *values[] = {
kSecClassGenericPassword
, kSecAttrAccessibleWhenUnlocked
, (__bridge CFStringRef)service
, (__bridge CFStringRef)account
, data //CFDataRef
};
什麼是 「鑰匙」 和 「價值觀」 聲明? –
添加到問題 – Haagenti