2014-05-16 2 views
0

래퍼없이 KeyChain을 사용하려고합니다. 하지만 값을 읽을 때 코드가 다운됩니다.iOS KeyChain secItemAdd 충돌 발생

코드 :

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 
}; 
+0

"키"와 "값"으로 무엇을 선언? –

+0

질문에 추가 – Haagenti

답변

2

:

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.

+0

이 작업은 SecItemCopyMatching에서만 수행되어야한다고 생각했습니다. 고맙습니다! – Haagenti

-1

당신이 EXC_BAD_ACCESS를 얻고있는 이유에 대한 대답은, 때문에 당신이에 합격 사전 SecItemAdd는 변경 가능해야합니다. 이 같은

시도 뭔가 :

CFMutableDictionaryRef attributes = CFDictionaryCreateMutable(NULL, size, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

CFDictionaryAddValue(attributes, keys[x], values[x]);

관련 문제