Determines at runtime is UIApplication is available as per #1082
This commit is contained in:
parent
f2252b3499
commit
17a4803661
|
@ -474,6 +474,10 @@ BOOL ImageDataHasPNGPreffix(NSData *data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)backgroundCleanDisk {
|
- (void)backgroundCleanDisk {
|
||||||
|
Class UIApplicationClass = NSClassFromString(@"UIApplication");
|
||||||
|
if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
UIApplication *application = [UIApplication sharedApplication];
|
UIApplication *application = [UIApplication sharedApplication];
|
||||||
__block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
|
__block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
|
||||||
// Clean up any unfinished task business by marking where you
|
// Clean up any unfinished task business by marking where you
|
||||||
|
|
|
@ -70,7 +70,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
|
#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
|
||||||
if ([self shouldContinueWhenAppEntersBackground]) {
|
Class UIApplicationClass = NSClassFromString(@"UIApplication");
|
||||||
|
BOOL hasApplication = UIApplicationClass && [UIApplicationClass respondsToSelector:@selector(sharedApplication)];
|
||||||
|
if (hasApplication && [self shouldContinueWhenAppEntersBackground]) {
|
||||||
__weak __typeof__ (self) wself = self;
|
__weak __typeof__ (self) wself = self;
|
||||||
self.backgroundTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
|
self.backgroundTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
|
||||||
__strong __typeof (wself) sself = wself;
|
__strong __typeof (wself) sself = wself;
|
||||||
|
@ -122,6 +124,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
|
#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
|
||||||
|
Class UIApplicationClass = NSClassFromString(@"UIApplication");
|
||||||
|
if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (self.backgroundTaskId != UIBackgroundTaskInvalid) {
|
if (self.backgroundTaskId != UIBackgroundTaskInvalid) {
|
||||||
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskId];
|
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskId];
|
||||||
self.backgroundTaskId = UIBackgroundTaskInvalid;
|
self.backgroundTaskId = UIBackgroundTaskInvalid;
|
||||||
|
|
Loading…
Reference in New Issue