diff --git a/CHANGELOG.md b/CHANGELOG.md index 5490ed61..9486e4fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - [new] Add PINRemoteImageManagerConfiguration configuration object. [#492](https://github.com/pinterest/PINRemoteImage/pull/492) [rqueue](https://github.com/rqueue) - [fixed] Fixes blending in animated WebP images. [#507](https://github.com/pinterest/PINRemoteImage/pull/507) [garrettmoon](https://github.com/garrettmoon) - [fixed] Fixes support in PINAnimatedImageView for WebP animated images. [#507](https://github.com/pinterest/PINRemoteImage/pull/507) [garrettmoon](https://github.com/garrettmoon) +- [new] Exposure didCompleteTask:withError: delegate method of protocol PINURLSessionManagerDelegate. [#519](https://github.com/pinterest/PINRemoteImage/pull/519) [zhongwuzw](https://github.com/zhongwuzw) - [fixed] Fixes AnimatedImageView designated initializer not work. [#512](https://github.com/pinterest/PINRemoteImage/pull/512) [zhongwuzw](https://github.com/zhongwuzw) - [fixed] Set bpp(bits per pixel) to 32 bit for GIF. [#511](https://github.com/pinterest/PINRemoteImage/pull/511) [zhongwuzw](https://github.com/zhongwuzw) - [new] Add cancel method for PINRemoteImageManager. [#509](https://github.com/pinterest/PINRemoteImage/pull/509) [zhongwuzw](https://github.com/zhongwuzw) diff --git a/Source/Classes/PINURLSessionManager.h b/Source/Classes/PINURLSessionManager.h index 3b170176..5b25ff17 100644 --- a/Source/Classes/PINURLSessionManager.h +++ b/Source/Classes/PINURLSessionManager.h @@ -21,7 +21,7 @@ extern NSErrorDomain _Nonnull const PINURLErrorDomain; - (void)didCollectMetrics:(nonnull NSURLSessionTaskMetrics *)metrics forURL:(nonnull NSURL *)url API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)); - (void)didReceiveResponse:(nonnull NSURLResponse *)response forTask:(nonnull NSURLSessionTask *)task; - (void)didReceiveAuthenticationChallenge:(nonnull NSURLAuthenticationChallenge *)challenge forTask:(nullable NSURLSessionTask *)task completionHandler:(nonnull void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler; - +- (void)didCompleteTask:(nonnull NSURLSessionTask *)task withError:(nullable NSError *)error; @end diff --git a/Source/Classes/PINURLSessionManager.m b/Source/Classes/PINURLSessionManager.m index 2059b3b4..e83601cb 100644 --- a/Source/Classes/PINURLSessionManager.m +++ b/Source/Classes/PINURLSessionManager.m @@ -201,6 +201,10 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp if (completionHandler) { completionHandler(task, error); } + + if ([strongSelf.delegate respondsToSelector:@selector(didCompleteTask:withError:)]) { + [strongSelf.delegate didCompleteTask:task withError:error]; + } }); } diff --git a/Tests/PINRemoteImageTests.m b/Tests/PINRemoteImageTests.m index 6bf03d98..00be9876 100644 --- a/Tests/PINRemoteImageTests.m +++ b/Tests/PINRemoteImageTests.m @@ -89,6 +89,7 @@ @interface PINRemoteImage_Tests : XCTestCase @property (nonatomic, strong) NSMutableData *data; @property (nonatomic, strong) NSURLSessionTask *task; @property (nonatomic, strong) NSError *error; +@property (nonatomic, strong) dispatch_semaphore_t sessionDidCompleteDelegateSemaphore; @end @@ -222,6 +223,10 @@ - (void)didCompleteTask:(NSURLSessionTask *)task withError:(NSError *)error { self.task = task; self.error = error; + // Used for URLSessionDidCompleteDelegate test + if (self.sessionDidCompleteDelegateSemaphore) { + dispatch_semaphore_signal(self.sessionDidCompleteDelegateSemaphore); + } } - (void)setUp @@ -239,6 +244,9 @@ - (void)tearDown self.imageManager = nil; [[PINSpeedRecorder sharedRecorder] setCurrentBytesPerSecond:-1]; [[PINSpeedRecorder sharedRecorder] resetMeasurements]; + if (self.sessionDidCompleteDelegateSemaphore) { + self.sessionDidCompleteDelegateSemaphore = nil; + } [super tearDown]; } @@ -1410,6 +1418,16 @@ - (void)testRetry method_exchangeImplementations(originalMethod, swizzledMethod); } +- (void)testURLSessionDidCompleteDelegate +{ + self.imageManager = [[PINRemoteImageManager alloc] init]; + self.imageManager.sessionManager.delegate = self; + self.sessionDidCompleteDelegateSemaphore = dispatch_semaphore_create(0); + [self.imageManager downloadImageWithURL:[self transparentPNGURL] completion:nil]; + long result = dispatch_semaphore_wait(self.sessionDidCompleteDelegateSemaphore, [self timeout]); + XCTAssert(result == 0); +} + - (void)testCancelAllTasks { XCTestExpectation *expectation = [self expectationWithDescription:@"Cancel all tasks"];