Skip to content

Commit

Permalink
Merge pull request AFNetworking#3490 from dchohfi/deprecating-method
Browse files Browse the repository at this point in the history
Added deprecated attribute to  `dataTaskWithRequest:completionHandler:`
  • Loading branch information
kcharwood committed May 6, 2016
2 parents e1e2d62 + 11c049a commit 59d5111
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion AFNetworking/AFURLSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ NS_ASSUME_NONNULL_BEGIN
@param completionHandler A block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any.
*/
- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request
completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler;
completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler DEPRECATED_ATTRIBUTE;

/**
Creates an `NSURLSessionDataTask` with the specified request.
Expand Down
9 changes: 6 additions & 3 deletions Tests/Tests/AFHTTPSessionManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ - (void)testThatOperationInvokesCompletionHandlerWithResponseObjectOnSuccess {
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/get" relativeToURL:self.baseURL]];
NSURLSessionDataTask *task = [self.manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
NSURLSessionDataTask *task = [self.manager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
blockResponseObject = responseObject;
blockError = error;
[expectation fulfill];
Expand All @@ -75,7 +76,8 @@ - (void)testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure {
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/status/404" relativeToURL:self.baseURL]];
NSURLSessionDataTask *task = [self.manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
NSURLSessionDataTask *task = [self.manager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
blockError = error;
[expectation fulfill];
}];
Expand All @@ -95,7 +97,8 @@ - (void)testThatRedirectBlockIsCalledWhen302IsEncountered {
XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];

NSURLRequest *redirectRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/redirect/1" relativeToURL:self.baseURL]];
NSURLSessionDataTask *redirectTask = [self.manager dataTaskWithRequest:redirectRequest completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
NSURLSessionDataTask *redirectTask = [self.manager dataTaskWithRequest:redirectRequest uploadProgress:nil downloadProgress:nil
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
blockError = error;
[expectation fulfill];
}];
Expand Down
6 changes: 6 additions & 0 deletions Tests/Tests/AFUIActivityIndicatorViewTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ - (void)testTaskDidResumeNotificationDoesNotCauseCrashForAIVWithTask {
[self expectationForNotification:AFNetworkingTaskDidResumeNotification object:nil handler:nil];
NSURLSessionDataTask *task = [self.sessionManager
dataTaskWithRequest:self.request
uploadProgress:nil
downloadProgress:nil
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
[expectation fulfill];
}];
Expand All @@ -67,6 +69,8 @@ - (void)testTaskDidCompleteNotificationDoesNotCauseCrashForAIVWithTask {
[self expectationForNotification:AFNetworkingTaskDidCompleteNotification object:nil handler:nil];
NSURLSessionDataTask *task = [self.sessionManager
dataTaskWithRequest:self.request
uploadProgress:nil
downloadProgress:nil
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
//Without the dispatch after, this test would PASS errorenously because the test
//would finish before the notification was posted to all objects that were
Expand All @@ -89,6 +93,8 @@ - (void)testTaskDidSuspendNotificationDoesNotCauseCrashForAIVWithTask {
[self expectationForNotification:AFNetworkingTaskDidSuspendNotification object:nil handler:nil];
NSURLSessionDataTask *task = [self.sessionManager
dataTaskWithRequest:self.request
uploadProgress:nil
downloadProgress:nil
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
//Without the dispatch after, this test would PASS errorenously because the test
//would finish before the notification was posted to all objects that were
Expand Down
6 changes: 6 additions & 0 deletions Tests/Tests/AFUIRefreshControlTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ - (void)testTaskDidResumeNotificationDoesNotCauseCrashForUIRCWithTask {
[self expectationForNotification:AFNetworkingTaskDidResumeNotification object:nil handler:nil];
NSURLSessionDataTask *task = [self.sessionManager
dataTaskWithRequest:self.request
uploadProgress:nil
downloadProgress:nil
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
[expectation fulfill];
}];
Expand All @@ -66,6 +68,8 @@ - (void)testTaskDidCompleteNotificationDoesNotCauseCrashForUIRCWithTask {
[self expectationForNotification:AFNetworkingTaskDidCompleteNotification object:nil handler:nil];
NSURLSessionDataTask *task = [self.sessionManager
dataTaskWithRequest:self.request
uploadProgress:nil
downloadProgress:nil
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
//Without the dispatch after, this test would PASS errorenously because the test
//would finish before the notification was posted to all objects that were
Expand All @@ -88,6 +92,8 @@ - (void)testTaskDidSuspendNotificationDoesNotCauseCrashForUIRCWithTask {
[self expectationForNotification:AFNetworkingTaskDidSuspendNotification object:nil handler:nil];
NSURLSessionDataTask *task = [self.sessionManager
dataTaskWithRequest:self.request
uploadProgress:nil
downloadProgress:nil
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
//Without the dispatch after, this test would PASS errorenously because the test
//would finish before the notification was posted to all objects that were
Expand Down
32 changes: 23 additions & 9 deletions Tests/Tests/AFURLSessionManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ - (void)testRDAR17029580IsFixed {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
task = [self.localManager
dataTaskWithRequest:[NSURLRequest requestWithURL:self.baseURL]
uploadProgress:nil
downloadProgress:nil
completionHandler:nil];
dispatch_sync(serial_queue, ^{
XCTAssertFalse([taskIDs containsObject:@(task.taskIdentifier)]);
Expand All @@ -204,19 +206,25 @@ - (void)testRDAR17029580IsFixed {

- (void)testDidResumeNotificationIsReceivedByLocalDataTaskAfterResume {
NSURLSessionDataTask *task = [self.localManager dataTaskWithRequest:[self _delayURLRequest]
completionHandler:nil];
uploadProgress:nil
downloadProgress:nil
completionHandler:nil];
[self _testResumeNotificationForTask:task];
}

- (void)testDidSuspendNotificationIsReceivedByLocalDataTaskAfterSuspend {
NSURLSessionDataTask *task = [self.localManager dataTaskWithRequest:[self _delayURLRequest]
completionHandler:nil];
uploadProgress:nil
downloadProgress:nil
completionHandler:nil];
[self _testSuspendNotificationForTask:task];
}

- (void)testDidResumeNotificationIsReceivedByBackgroundDataTaskAfterResume {
if (self.backgroundManager) {
NSURLSessionDataTask *task = [self.backgroundManager dataTaskWithRequest:[self _delayURLRequest]
uploadProgress:nil
downloadProgress:nil
completionHandler:nil];
[self _testResumeNotificationForTask:task];
}
Expand All @@ -225,24 +233,26 @@ - (void)testDidResumeNotificationIsReceivedByBackgroundDataTaskAfterResume {
- (void)testDidSuspendNotificationIsReceivedByBackgroundDataTaskAfterSuspend {
if (self.backgroundManager) {
NSURLSessionDataTask *task = [self.backgroundManager dataTaskWithRequest:[self _delayURLRequest]
uploadProgress:nil
downloadProgress:nil
completionHandler:nil];
[self _testSuspendNotificationForTask:task];
}
}

- (void)testDidResumeNotificationIsReceivedByLocalUploadTaskAfterResume {
NSURLSessionUploadTask *task = [self.localManager uploadTaskWithRequest:[self _delayURLRequest]
fromData:[NSData data]
progress:nil
completionHandler:nil];
fromData:[NSData data]
progress:nil
completionHandler:nil];
[self _testResumeNotificationForTask:task];
}

- (void)testDidSuspendNotificationIsReceivedByLocalUploadTaskAfterSuspend {
NSURLSessionUploadTask *task = [self.localManager uploadTaskWithRequest:[self _delayURLRequest]
fromData:[NSData data]
progress:nil
completionHandler:nil];
fromData:[NSData data]
progress:nil
completionHandler:nil];
[self _testSuspendNotificationForTask:task];
}

Expand Down Expand Up @@ -318,7 +328,9 @@ - (void)testSwizzlingIsProperlyConfiguredForDummyClass {

- (void)testSwizzlingIsWorkingAsExpectedForForegroundDataTask {
NSURLSessionTask *task = [self.localManager dataTaskWithRequest:[self _delayURLRequest]
completionHandler:nil];
uploadProgress:nil
downloadProgress:nil
completionHandler:nil];
[self _testSwizzlingForTask:task];
[task cancel];
}
Expand Down Expand Up @@ -368,6 +380,8 @@ - (void)testSwizzlingIsWorkingAsExpectedForBackgroundDownloadTask {
- (void)testBackgroundManagerReturnsExpectedClassForDataTask {
if (self.backgroundManager) {
NSURLSessionTask *task = [self.backgroundManager dataTaskWithRequest:[self _delayURLRequest]
uploadProgress:nil
downloadProgress:nil
completionHandler:nil];
XCTAssert([NSStringFromClass([task class]) isEqualToString:@"__NSCFBackgroundDataTask"]);
} else {
Expand Down
2 changes: 2 additions & 0 deletions UIKit+AFNetworking/AFImageDownloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ - (nullable AFImageDownloadReceipt *)downloadImageForURLRequest:(NSURLRequest *)

createdTask = [self.sessionManager
dataTaskWithRequest:request
uploadProgress:nil
downloadProgress:nil
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
dispatch_async(self.responseQueue, ^{
__strong __typeof__(weakSelf) strongSelf = weakSelf;
Expand Down

0 comments on commit 59d5111

Please sign in to comment.