Skip to content

Fixes some issues around Xcode 9 yelling about using UIKit on background threads #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions FastImageCache/FastImageCache/FastImageCache/FICImageTable.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
static NSString *const FICImageTableMRUArrayKey = @"mruArray";
static NSString *const FICImageTableFormatKey = @"format";

static BOOL FICProtectedDataAvailable = NO;

#pragma mark - Class Extension

@interface FICImageTable () {
Expand Down Expand Up @@ -134,6 +136,29 @@ + (NSString *)directoryPath {
return __directoryPath;
}

+ (void)initialize {
[self registerForProtectedDataNotifications];
}

+ (void)registerForProtectedDataNotifications {
dispatch_async(dispatch_get_main_queue(), ^{
UIApplication *application = [UIApplication performSelector:@selector(sharedApplication)];
if (application) {
FICProtectedDataAvailable = [application isProtectedDataAvailable];
}
});
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(protectedDataWillBecomeUnavailable:) name:UIApplicationProtectedDataWillBecomeUnavailable object:nil];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(protectedDataDidBecomeAvailable:) name:UIApplicationProtectedDataDidBecomeAvailable object:nil];
}

+ (void)protectedDataWillBecomeUnavailable:(id)sender {
FICProtectedDataAvailable = NO;
}
+ (void)protectedDataDidBecomeAvailable:(id)sender {
FICProtectedDataAvailable = YES;
}


#pragma mark - Object Lifecycle

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

self = nil;
}
}
}

return self;
Expand Down Expand Up @@ -518,10 +543,8 @@ - (BOOL)canAccessEntryData {

// -[UIApplication isProtectedDataAvailable] checks whether the keybag is locked or not
UIApplication *application = [UIApplication performSelector:@selector(sharedApplication)];
if (application) {
_canAccessData = [application isProtectedDataAvailable];
}

_canAccessData = FICProtectedDataAvailable;

// We have to fallback to a direct check on the file if either:
// - The application doesn't exist (happens in some extensions)
// - The keybag is locked, but the file might still be accessible because the mode is "until first user authentication"
Expand Down