mismo error para mí, he comprobado el valor de retorno para writeToKeychain
función en KeychainItemWrapper.m
archivo. El valor de retorno es igual a errSecDuplicateItem
. No sé por qué pero parece que la función SecItemCopyMatching
no funciona correctamente. (Para que mi otro proyecto funcione correctamente).
me cambiaron los códigos para el presente y trabajando para mí: códigos actualizados para writeToKeychain
en KeychainItemWrapper.m
archivo:
- (void)writeToKeychain
{
NSDictionary *attributes = NULL;
NSMutableDictionary *updateItem = NULL;
OSStatus result;
if (SecItemCopyMatching((CFDictionaryRef)genericPasswordQuery, (CFTypeRef *)&attributes) == noErr)
{
// First we need the attributes from the Keychain.
updateItem = [NSMutableDictionary dictionaryWithDictionary:attributes];
// Second we need to add the appropriate search key/values.
[updateItem setObject:[genericPasswordQuery objectForKey:(id)kSecClass] forKey:(id)kSecClass];
// Lastly, we need to set up the updated attribute list being careful to remove the class.
NSMutableDictionary *tempCheck = [self dictionaryToSecItemFormat:keychainItemData];
[tempCheck removeObjectForKey:(id)kSecClass];
#if TARGET_IPHONE_SIMULATOR
// Remove the access group if running on the iPhone simulator.
//
// Apps that are built for the simulator aren't signed, so there's no keychain access group
// for the simulator to check. This means that all apps can see all keychain items when run
// on the simulator.
//
// If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the
// simulator will return -25243 (errSecNoAccessForItem).
//
// The access group attribute will be included in items returned by SecItemCopyMatching,
// which is why we need to remove it before updating the item.
[tempCheck removeObjectForKey:(id)kSecAttrAccessGroup];
#endif
// An implicit assumption is that you can only update a single item at a time.
result = SecItemUpdate((CFDictionaryRef)updateItem, (CFDictionaryRef)tempCheck);
NSAssert(result == noErr, @"Couldn't update the Keychain Item.");
}
else
{
// No previous item found; add the new one.
result = SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL);
NSLog(@"%@",keychainItemData);
NSLog(@"res : %ld",result);
if(result == (OSStatus)errSecDuplicateItem)
{
NSLog(@"updttttt");
// First we need the attributes from the Keychain.
updateItem = [NSMutableDictionary dictionaryWithDictionary:attributes];
// Second we need to add the appropriate search key/values.
[updateItem setObject:[genericPasswordQuery objectForKey:(id)kSecClass] forKey:(id)kSecClass];
// Lastly, we need to set up the updated attribute list being careful to remove the class.
NSMutableDictionary *tempCheck = [self dictionaryToSecItemFormat:keychainItemData];
[tempCheck removeObjectForKey:(id)kSecClass];
#if TARGET_IPHONE_SIMULATOR
// Remove the access group if running on the iPhone simulator.
//
// Apps that are built for the simulator aren't signed, so there's no keychain access group
// for the simulator to check. This means that all apps can see all keychain items when run
// on the simulator.
//
// If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the
// simulator will return -25243 (errSecNoAccessForItem).
//
// The access group attribute will be included in items returned by SecItemCopyMatching,
// which is why we need to remove it before updating the item.
[tempCheck removeObjectForKey:(id)kSecAttrAccessGroup];
#endif
// An implicit assumption is that you can only update a single item at a time.
result = SecItemUpdate((CFDictionaryRef)updateItem, (CFDictionaryRef)tempCheck);
NSAssert(result == noErr, @"Couldn't update the Keychain Item.");
return;
}//if(result == errSecDuplicateItem)*
NSAssert(result == noErr, @"Couldn't add the Keychain Item.");
}
}
¿Qué estaba capaz de imprimir? ¿Por qué no establece un punto de interrupción e inspecciona los objetos mientras se ejecuta? – vfn
Nada. Nada aparece cuando traté de imprimir los objetos. Al inspeccionarlos solo se muestra la dirección en la forma de 0xSOMETHING. –
@Anh pregunta estúpida, pero ¿has verificado que 'wrapper' no es nulo? Además, estoy de acuerdo con vfn sobre el establecimiento de puntos de interrupción ... –