Skip to content

Commit

Permalink
Merge pull request #102 from thomasvl/background_task_tweaks
Browse files Browse the repository at this point in the history
Remove direct use of UIApplication from GTLR.
  • Loading branch information
thomasvl committed Mar 13, 2017
2 parents ac844a2 + d6c2dc3 commit a630e1b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Source/Objects/GTLRService.m
Original file line number Diff line number Diff line change
Expand Up @@ -2578,7 +2578,22 @@ - (void)cancelTicket {
id<GTMUIApplicationProtocol> app = [GTMSessionFetcher substituteUIApplication];
if (app) return app;

return (id<GTMUIApplicationProtocol>)[UIApplication sharedApplication];
static Class applicationClass = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
BOOL isAppExtension = [[[NSBundle mainBundle] bundlePath] hasSuffix:@".appex"];
if (!isAppExtension) {
Class cls = NSClassFromString(@"UIApplication");
if (cls && [cls respondsToSelector:NSSelectorFromString(@"sharedApplication")]) {
applicationClass = cls;
}
}
});

if (applicationClass) {
app = (id<GTMUIApplicationProtocol>)[applicationClass sharedApplication];
}
return app;
}
#endif // GTM_BACKGROUND_TASK_FETCHING

Expand Down

0 comments on commit a630e1b

Please sign in to comment.