@@ -63,7 +63,8 @@ @interface FICImageTable () {
6363 NSCountedSet *_inUseEntries;
6464 NSDictionary *_imageFormatDictionary;
6565
66- BOOL _isFileDataProtected;
66+ NSString *_fileDataProtectionMode;
67+ BOOL _canAccessData;
6768}
6869@property (nonatomic , weak ) FICImageCache *imageCache;
6970@end
@@ -172,10 +173,7 @@ - (instancetype)initWithFormat:(FICImageFormat *)imageFormat imageCache:(FICImag
172173 }
173174
174175 NSDictionary *attributes = [fileManager attributesOfItemAtPath: _filePath error: NULL ];
175- NSString *protectionMode = [attributes objectForKey: NSFileProtectionKey ];
176- if (protectionMode) {
177- _isFileDataProtected = [protectionMode isEqualToString: NSFileProtectionNone ] == NO ;
178- }
176+ _fileDataProtectionMode = [attributes objectForKey: NSFileProtectionKey ];
179177
180178 _fileDescriptor = open ([_filePath fileSystemRepresentation ], O_RDWR | O_CREAT, 0666 );
181179
@@ -496,8 +494,20 @@ - (void)_setEntryCount:(NSInteger)entryCount {
496494// by using NSFileProtectionNone
497495- (BOOL )canAccessEntryData {
498496 BOOL result = YES ;
499- if (_isFileDataProtected ) {
497+ if ([_fileDataProtectionMode isEqualToString: NSFileProtectionComplete ] ) {
500498 result = [[UIApplication sharedApplication ] isProtectedDataAvailable ];
499+ } else if ([_fileDataProtectionMode isEqualToString: NSFileProtectionCompleteUntilFirstUserAuthentication ]) {
500+ // For "complete until first auth", if we were previously able to access data, then we'll still be able to
501+ // access it. If we haven't yet been able to access data, we'll need to try until we are successful.
502+ if (_canAccessData == NO ) {
503+ if ([[UIApplication sharedApplication ] isProtectedDataAvailable ]) {
504+ // we are unlocked, so we're good to go.
505+ _canAccessData = YES ;
506+ } else {
507+ // we are locked, so try to access data.
508+ _canAccessData = [NSData dataWithContentsOfMappedFile: _filePath] != nil ;
509+ }
510+ }
501511 }
502512 return result;
503513}
0 commit comments