I am setting the kSecAttrAccessibleWhenUnlocked
key when adding a value to the keychain. The documentation states:
The data in the keychain item can be accessed only while the device is unlocked by the user.
I wrote a simple test app, here is the viewDidLoad
method:
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
// Device (with passcode lock) is locked now
double delayInSeconds = 6.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
NSError * error = nil;
[MyKeychainWrapper setKeychainObject:@"abc"
forKey:@"key"
error:&error];
NSLog(@"Setting Error: %@", error); // No error logged
NSString * value = (NSString *) [MyKeychainWrapper keychainObjectForKey:@"key"
error:&error];
NSLog(@"value: %@", value); // Logs ABC when the device is locked
NSLog(@"Getting Error: %@", error); // No error logged
});
How is it saving and reading the data while the device is locked?