Revert the "Don't encode/decode image when app will terminate"
This commit is contained in:
parent
d1c75d8397
commit
bed1638b42
|
@ -13,7 +13,6 @@
|
|||
#import "SDImageCoderHelper.h"
|
||||
#import "SDAnimatedImageRep.h"
|
||||
#import "UIImage+ForceDecode.h"
|
||||
#import "SDInternalMacros.h"
|
||||
|
||||
// Specify DPI for vector format in CGImageSource, like PDF
|
||||
static NSString * kSDCGImageSourceRasterizationDPI = @"kCGImageSourceRasterizationDPI";
|
||||
|
@ -30,9 +29,6 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
|
|||
@implementation SDImageIOCoderFrame
|
||||
@end
|
||||
|
||||
static BOOL applicationWillTerminate = NO;
|
||||
SD_LOCK_DECLARE_STATIC(applicationWillTerminateLock);
|
||||
|
||||
@implementation SDImageIOAnimatedCoder {
|
||||
size_t _width, _height;
|
||||
CGImageSourceRef _imageSource;
|
||||
|
@ -46,39 +42,8 @@ SD_LOCK_DECLARE_STATIC(applicationWillTerminateLock);
|
|||
CGSize _thumbnailSize;
|
||||
}
|
||||
|
||||
+ (void)initialize {
|
||||
if (self == SDImageIOAnimatedCoder.class) {
|
||||
SD_LOCK_INIT(applicationWillTerminateLock);
|
||||
#if SD_UIKIT
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationWillTerminate:)
|
||||
name:UIApplicationWillTerminateNotification
|
||||
object:nil];
|
||||
|
||||
#endif
|
||||
#if SD_MAC
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationWillTerminate:)
|
||||
name:NSApplicationWillTerminateNotification
|
||||
object:nil];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)applicationWillTerminate:(NSNotification *)notification {
|
||||
SD_LOCK(applicationWillTerminateLock);
|
||||
applicationWillTerminate = YES;
|
||||
SD_UNLOCK(applicationWillTerminateLock);
|
||||
}
|
||||
|
||||
+ (BOOL)willTerminate {
|
||||
SD_LOCK(applicationWillTerminateLock);
|
||||
BOOL willTerminate = applicationWillTerminate;
|
||||
SD_UNLOCK(applicationWillTerminateLock);
|
||||
return willTerminate;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
- (void)dealloc
|
||||
{
|
||||
if (_imageSource) {
|
||||
CFRelease(_imageSource);
|
||||
_imageSource = NULL;
|
||||
|
@ -88,7 +53,8 @@ SD_LOCK_DECLARE_STATIC(applicationWillTerminateLock);
|
|||
#endif
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning:(NSNotification *)notification {
|
||||
- (void)didReceiveMemoryWarning:(NSNotification *)notification
|
||||
{
|
||||
if (_imageSource) {
|
||||
for (size_t i = 0; i < _frameCount; i++) {
|
||||
CGImageSourceRemoveCacheAtIndex(_imageSource, i);
|
||||
|
@ -222,11 +188,6 @@ SD_LOCK_DECLARE_STATIC(applicationWillTerminateLock);
|
|||
}
|
||||
|
||||
+ (UIImage *)createFrameAtIndex:(NSUInteger)index source:(CGImageSourceRef)source scale:(CGFloat)scale preserveAspectRatio:(BOOL)preserveAspectRatio thumbnailSize:(CGSize)thumbnailSize options:(NSDictionary *)options {
|
||||
// Earily return when application will be terminated.
|
||||
if (SDImageIOAnimatedCoder.willTerminate) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Some options need to pass to `CGImageSourceCopyPropertiesAtIndex` before `CGImageSourceCreateImageAtIndex`, or ImageIO will ignore them because they parse once :)
|
||||
// Parse the image properties
|
||||
NSDictionary *properties = (__bridge_transfer NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source, index, (__bridge CFDictionaryRef)options);
|
||||
|
@ -414,11 +375,11 @@ SD_LOCK_DECLARE_STATIC(applicationWillTerminateLock);
|
|||
CGSize thumbnailSize = CGSizeZero;
|
||||
NSValue *thumbnailSizeValue = options[SDImageCoderDecodeThumbnailPixelSize];
|
||||
if (thumbnailSizeValue != nil) {
|
||||
#if SD_MAC
|
||||
#if SD_MAC
|
||||
thumbnailSize = thumbnailSizeValue.sizeValue;
|
||||
#else
|
||||
#else
|
||||
thumbnailSize = thumbnailSizeValue.CGSizeValue;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
_thumbnailSize = thumbnailSize;
|
||||
BOOL preserveAspectRatio = YES;
|
||||
|
@ -435,10 +396,6 @@ SD_LOCK_DECLARE_STATIC(applicationWillTerminateLock);
|
|||
}
|
||||
|
||||
- (void)updateIncrementalData:(NSData *)data finished:(BOOL)finished {
|
||||
// Earily return when application will be terminated.
|
||||
if (SDImageIOAnimatedCoder.willTerminate) {
|
||||
return;
|
||||
}
|
||||
if (_finished) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -138,10 +138,6 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
|
|||
}
|
||||
|
||||
- (void)updateIncrementalData:(NSData *)data finished:(BOOL)finished {
|
||||
// Earily return when application will be terminated.
|
||||
if (SDImageIOAnimatedCoder.willTerminate) {
|
||||
return;
|
||||
}
|
||||
if (_finished) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,5 @@
|
|||
+ (nullable UIImage *)createFrameAtIndex:(NSUInteger)index source:(nonnull CGImageSourceRef)source scale:(CGFloat)scale preserveAspectRatio:(BOOL)preserveAspectRatio thumbnailSize:(CGSize)thumbnailSize options:(nullable NSDictionary *)options;
|
||||
+ (BOOL)canEncodeToFormat:(SDImageFormat)format;
|
||||
+ (BOOL)canDecodeFromFormat:(SDImageFormat)format;
|
||||
+ (BOOL)willTerminate;
|
||||
|
||||
@end
|
||||
|
|
|
@ -311,26 +311,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void)test22DoNotDecodeImageWhenApplicationWillTerminate {
|
||||
[[SDImageCodersManager sharedManager] addCoder:SDImageIOCoder.sharedCoder];
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"doNotDecodeImageWhenApplicationWillTerminate"];
|
||||
NSString *testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImageLarge" ofType:@"png"];
|
||||
NSData *testImageData = [NSData dataWithContentsOfFile:testImagePath];
|
||||
[[SDImageCache sharedImageCache] storeImageDataToDisk:testImageData forKey:@"TestImageLarge"];
|
||||
NSOperation *operation = [[SDImageCache sharedImageCache] queryCacheOperationForKey:@"TestImageLarge" done:^(UIImage *image, NSData *data, SDImageCacheType cacheType) {
|
||||
expect(data).to.equal(testImageData);
|
||||
expect(image).to.beNil;
|
||||
[[SDImageCache sharedImageCache] removeImageForKey:@"TestImageLarge" withCompletion:^{
|
||||
[expectation fulfill];
|
||||
}];
|
||||
}];
|
||||
expect(operation).toNot.beNil;
|
||||
[operation start];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillTerminateNotification object:nil];
|
||||
|
||||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
#pragma mark - Utils
|
||||
|
||||
- (void)verifyCoder:(id<SDImageCoder>)coder
|
||||
|
|
Loading…
Reference in New Issue