Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposure didCompleteTask:withError: delegate method of protocol PINURLSessionManagerDelegate #519

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Source/Classes/PINURLSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions Source/Classes/PINURLSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
});
}

Expand Down
18 changes: 18 additions & 0 deletions Tests/PINRemoteImageTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ @interface PINRemoteImage_Tests : XCTestCase <PINURLSessionManagerDelegate>
@property (nonatomic, strong) NSMutableData *data;
@property (nonatomic, strong) NSURLSessionTask *task;
@property (nonatomic, strong) NSError *error;
@property (nonatomic, strong) dispatch_semaphore_t sessionDidCompleteDelegateSemaphore;

@end

Expand Down Expand Up @@ -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
Expand All @@ -239,6 +244,9 @@ - (void)tearDown
self.imageManager = nil;
[[PINSpeedRecorder sharedRecorder] setCurrentBytesPerSecond:-1];
[[PINSpeedRecorder sharedRecorder] resetMeasurements];
if (self.sessionDidCompleteDelegateSemaphore) {
self.sessionDidCompleteDelegateSemaphore = nil;
}
[super tearDown];
}

Expand Down Expand Up @@ -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"];
Expand Down