Posts

Post not yet marked as solved
34 Replies
25k Views
I am facing a strange issue in my app. My code saves a string password in the iOS keychain to be accessed later on. It works just fine most of the times and I am able to fetch the password back after reinstallation or device restart or both.Problem: Sometimes which is actually rare and hard to reproduce, it does NOT return the password and instead it returns null and error status:-25300(errSecItemNotFound). Another thing is that this problem got prominent after iOS 9 update. Happening on iOS 9.1 too.Code for setting:NSMutableDictionary *query = [self _queryForService:service account:account]; [query setObject:password forKey:(__bridge id)kSecValueData]; status = SecItemAdd((__bridge CFDictionaryRef)query, NULL); if (status != errSecSuccess && error != NULL) { *error = [NSError errorWithDomain:kAppKeychainErrorDomain code:status userInfo:nil]; } return (status == noErr);Code for fetching:CFTypeRef result = NULL; NSMutableDictionary *query = [self _queryForService:service account:account]; [query setObject:(__bridge id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData]; [query setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit]; status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &result); if (status != errSecSuccess && error != NULL) { *error = [NSError errorWithDomain:kAppKeychainErrorDomain code:status userInfo:nil]; return nil; } return (__bridge_transfer NSData *)result;Has anyone got any ideas why this is happening? Many thanks.
Posted Last updated
.