|
31 | 31 | static NSString *const FICImageTableMRUArrayKey = @"mruArray"; |
32 | 32 | static NSString *const FICImageTableFormatKey = @"format"; |
33 | 33 |
|
| 34 | +static BOOL FICProtectedDataAvailable = NO; |
| 35 | + |
34 | 36 | #pragma mark - Class Extension |
35 | 37 |
|
36 | 38 | @interface FICImageTable () { |
@@ -134,6 +136,29 @@ + (NSString *)directoryPath { |
134 | 136 | return __directoryPath; |
135 | 137 | } |
136 | 138 |
|
| 139 | ++ (void)initialize { |
| 140 | + [self registerForProtectedDataNotifications]; |
| 141 | +} |
| 142 | + |
| 143 | ++ (void)registerForProtectedDataNotifications { |
| 144 | + dispatch_async(dispatch_get_main_queue(), ^{ |
| 145 | + UIApplication *application = [UIApplication performSelector:@selector(sharedApplication)]; |
| 146 | + if (application) { |
| 147 | + FICProtectedDataAvailable = [application isProtectedDataAvailable]; |
| 148 | + } |
| 149 | + }); |
| 150 | + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(protectedDataWillBecomeUnavailable:) name:UIApplicationProtectedDataWillBecomeUnavailable object:nil]; |
| 151 | + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(protectedDataDidBecomeAvailable:) name:UIApplicationProtectedDataDidBecomeAvailable object:nil]; |
| 152 | +} |
| 153 | + |
| 154 | ++ (void)protectedDataWillBecomeUnavailable:(id)sender { |
| 155 | + FICProtectedDataAvailable = NO; |
| 156 | +} |
| 157 | ++ (void)protectedDataDidBecomeAvailable:(id)sender { |
| 158 | + FICProtectedDataAvailable = YES; |
| 159 | +} |
| 160 | + |
| 161 | + |
137 | 162 | #pragma mark - Object Lifecycle |
138 | 163 |
|
139 | 164 | - (instancetype)initWithFormat:(FICImageFormat *)imageFormat imageCache:(FICImageCache *)imageCache { |
@@ -227,7 +252,7 @@ - (instancetype)initWithFormat:(FICImageFormat *)imageFormat imageCache:(FICImag |
227 | 252 | [self.imageCache _logMessage:message]; |
228 | 253 |
|
229 | 254 | self = nil; |
230 | | - } |
| 255 | + } |
231 | 256 | } |
232 | 257 |
|
233 | 258 | return self; |
@@ -518,10 +543,8 @@ - (BOOL)canAccessEntryData { |
518 | 543 |
|
519 | 544 | // -[UIApplication isProtectedDataAvailable] checks whether the keybag is locked or not |
520 | 545 | UIApplication *application = [UIApplication performSelector:@selector(sharedApplication)]; |
521 | | - if (application) { |
522 | | - _canAccessData = [application isProtectedDataAvailable]; |
523 | | - } |
524 | | - |
| 546 | + _canAccessData = FICProtectedDataAvailable; |
| 547 | + |
525 | 548 | // We have to fallback to a direct check on the file if either: |
526 | 549 | // - The application doesn't exist (happens in some extensions) |
527 | 550 | // - The keybag is locked, but the file might still be accessible because the mode is "until first user authentication" |
|
0 commit comments