Skip to content

Commit 79b82d6

Browse files
author
Robert Tolar Haining
committed
Fixes some issues around Xcode 9 yelling about using UIKit on background threads
1 parent 2615d27 commit 79b82d6

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

FastImageCache/FastImageCache/FastImageCache/FICImageTable.m

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
static NSString *const FICImageTableMRUArrayKey = @"mruArray";
3232
static NSString *const FICImageTableFormatKey = @"format";
3333

34+
static BOOL FICProtectedDataAvailable = NO;
35+
3436
#pragma mark - Class Extension
3537

3638
@interface FICImageTable () {
@@ -134,6 +136,29 @@ + (NSString *)directoryPath {
134136
return __directoryPath;
135137
}
136138

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+
137162
#pragma mark - Object Lifecycle
138163

139164
- (instancetype)initWithFormat:(FICImageFormat *)imageFormat imageCache:(FICImageCache *)imageCache {
@@ -227,7 +252,7 @@ - (instancetype)initWithFormat:(FICImageFormat *)imageFormat imageCache:(FICImag
227252
[self.imageCache _logMessage:message];
228253

229254
self = nil;
230-
}
255+
}
231256
}
232257

233258
return self;
@@ -518,10 +543,8 @@ - (BOOL)canAccessEntryData {
518543

519544
// -[UIApplication isProtectedDataAvailable] checks whether the keybag is locked or not
520545
UIApplication *application = [UIApplication performSelector:@selector(sharedApplication)];
521-
if (application) {
522-
_canAccessData = [application isProtectedDataAvailable];
523-
}
524-
546+
_canAccessData = FICProtectedDataAvailable;
547+
525548
// We have to fallback to a direct check on the file if either:
526549
// - The application doesn't exist (happens in some extensions)
527550
// - The keybag is locked, but the file might still be accessible because the mode is "until first user authentication"

0 commit comments

Comments
 (0)