From 17a48036610895931767b98497ec2f154053c0ce Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Fri, 20 Mar 2015 15:29:28 -0400 Subject: [PATCH 1/3] Determines at runtime is UIApplication is available as per #1082 --- SDWebImage/SDImageCache.m | 4 ++++ SDWebImage/SDWebImageDownloaderOperation.m | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index 00529037..f2f68177 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -474,6 +474,10 @@ BOOL ImageDataHasPNGPreffix(NSData *data) { } - (void)backgroundCleanDisk { + Class UIApplicationClass = NSClassFromString(@"UIApplication"); + if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) { + return; + } UIApplication *application = [UIApplication sharedApplication]; __block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{ // Clean up any unfinished task business by marking where you diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 025a0804..2cd58801 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -70,7 +70,9 @@ } #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; self.backgroundTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ __strong __typeof (wself) sself = wself; @@ -122,6 +124,10 @@ } #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) { [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskId]; self.backgroundTaskId = UIBackgroundTaskInvalid; From a66a790eb2002f3b67be6d6f6ac751e422e08e9c Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Fri, 20 Mar 2015 18:37:55 -0400 Subject: [PATCH 2/3] Replaces direct calls to UIApplication by peformSelector --- SDWebImage.xcodeproj/project.pbxproj | 5 +++++ SDWebImage/SDImageCache.m | 2 +- SDWebImage/SDWebImageDownloaderOperation.m | 8 +++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/SDWebImage.xcodeproj/project.pbxproj b/SDWebImage.xcodeproj/project.pbxproj index f56f679f..9ff083a5 100644 --- a/SDWebImage.xcodeproj/project.pbxproj +++ b/SDWebImage.xcodeproj/project.pbxproj @@ -1095,6 +1095,7 @@ 4A2CAE131AB4BB5400B6BC39 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -1141,6 +1142,7 @@ 4A2CAE141AB4BB5400B6BC39 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -1232,6 +1234,7 @@ 53761323155AD0D5005750A4 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = NO; CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = NO; DEAD_CODE_STRIPPING = NO; @@ -1255,6 +1258,7 @@ 53761324155AD0D5005750A4 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = NO; CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = NO; DEAD_CODE_STRIPPING = NO; @@ -1415,6 +1419,7 @@ 4A2CAE141AB4BB5400B6BC39 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 531041DD157EAFA400BBABC3 /* Build configuration list for PBXNativeTarget "SDWebImage+MKAnnotation" */ = { isa = XCConfigurationList; diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index f2f68177..3a21e9c0 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -478,7 +478,7 @@ BOOL ImageDataHasPNGPreffix(NSData *data) { if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) { return; } - UIApplication *application = [UIApplication sharedApplication]; + UIApplication *application = [UIApplication performSelector:@selector(sharedApplication)]; __block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{ // Clean up any unfinished task business by marking where you // stopped or ending the task outright. diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 2cd58801..da4ba47c 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -74,13 +74,14 @@ BOOL hasApplication = UIApplicationClass && [UIApplicationClass respondsToSelector:@selector(sharedApplication)]; if (hasApplication && [self shouldContinueWhenAppEntersBackground]) { __weak __typeof__ (self) wself = self; - self.backgroundTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ + UIApplication * app = [UIApplicationClass performSelector:@selector(sharedApplication)]; + self.backgroundTaskId = [app beginBackgroundTaskWithExpirationHandler:^{ __strong __typeof (wself) sself = wself; if (sself) { [sself cancel]; - [[UIApplication sharedApplication] endBackgroundTask:sself.backgroundTaskId]; + [app endBackgroundTask:sself.backgroundTaskId]; sself.backgroundTaskId = UIBackgroundTaskInvalid; } }]; @@ -129,7 +130,8 @@ return; } if (self.backgroundTaskId != UIBackgroundTaskInvalid) { - [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskId]; + UIApplication * app = [UIApplication performSelector:@selector(sharedApplication)]; + [app endBackgroundTask:self.backgroundTaskId]; self.backgroundTaskId = UIBackgroundTaskInvalid; } #endif From a897811eb5e37da5914eeef5d413143c21fb73a6 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Sun, 22 Mar 2015 16:40:44 -0400 Subject: [PATCH 3/3] Lowers deployment target to 8.0 --- SDWebImage.xcodeproj/project.pbxproj | 4 +-- .../xcshareddata/xcschemes/WebImage.xcscheme | 33 ------------------- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/SDWebImage.xcodeproj/project.pbxproj b/SDWebImage.xcodeproj/project.pbxproj index 9ff083a5..4be5483c 100644 --- a/SDWebImage.xcodeproj/project.pbxproj +++ b/SDWebImage.xcodeproj/project.pbxproj @@ -1127,7 +1127,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = WebImage/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.3; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1172,7 +1172,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = WebImage/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.3; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/SDWebImage.xcworkspace/xcshareddata/xcschemes/WebImage.xcscheme b/SDWebImage.xcworkspace/xcshareddata/xcschemes/WebImage.xcscheme index eff4eec2..20121756 100644 --- a/SDWebImage.xcworkspace/xcshareddata/xcschemes/WebImage.xcscheme +++ b/SDWebImage.xcworkspace/xcshareddata/xcschemes/WebImage.xcscheme @@ -20,20 +20,6 @@ ReferencedContainer = "container:SDWebImage.xcodeproj"> - - - - - - - - - - - -