I would like to know if the device is locked when I load the Notification / Today widget, so I can show the widget correctly. (this is financial, and we don’t want to show balances on a locked phone)
On devices with TouchID, I can just try to access Keychain, and if I get
errSecInteractionNotAllowed
back, it is locked. Things are good. This does not work on devices without a touchID (but with a PIN). I found several things that recommend using
[[UIApplication sharedApplication] protectedDataAvailable]
However, I do not have [UIApplication sharedApplication]widgets.
Any ideas where and how to do this? I just need yes / no: the device is locked.
thank
[UPDATE: here is the code that I have]
Getting the file name:
+ (NSString *)lockedDeviceFilename {
NSURL *directoryUrl = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:USER_DEFAULTS_GROUP_NAME];
return [directoryUrl.path stringByAppendingPathComponent:@"security.dummy"];
}
/ ( , :
NSError *error = nil;
NSString *documentPath = [FOOStorageGatekeeper lockedDeviceFilename];
[[NSFileManager defaultManager] removeItemAtPath:documentPath error:&error];
BOOL created = [[NSFileManager defaultManager] createFileAtPath:documentPath
contents:[@"super secret file contents. we only care about the permissions" dataUsingEncoding:NSUTF8StringEncoding]
attributes:@{NSFileProtectionKey : NSFileProtectionComplete}];
:
BOOL isReadable = [[NSFileManager defaultManager] fileExistsAtPath:[FOOStorageGatekeeper lockedDeviceFilename]];
NSLog(@"isReadable? %@", isReadable ? @"YES" : @"NO");
, TouchID . , , NSFileProtectionKey NSFileProtectionComplete... : (
: .