Skip to content

Commit

Permalink
Xcode 7.x compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Caelin Jackson-King committed Jun 29, 2018
1 parent d0448a8 commit 63410f3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion AFNetworking/AFURLSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,9 @@ NS_ASSUME_NONNULL_BEGIN
@param block A block object to be executed when a session task is completed. The block has no return value, and takes three arguments: the session, the task, and any metrics that were collected in the process of executing the task.
*/
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
- (void)setTaskDidFinishCollectingMetricsBlock:(nullable void (^)(NSURLSession *session, NSURLSessionTask *task, NSURLSessionTaskMetrics * _Nullable metrics))block;

#endif
///-------------------------------------------
/// @name Setting Data Task Delegate Callbacks
///-------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion AFNetworking/AFURLSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ static dispatch_group_t url_session_manager_completion_group() {
typedef NSInputStream * (^AFURLSessionTaskNeedNewBodyStreamBlock)(NSURLSession *session, NSURLSessionTask *task);
typedef void (^AFURLSessionTaskDidSendBodyDataBlock)(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend);
typedef void (^AFURLSessionTaskDidCompleteBlock)(NSURLSession *session, NSURLSessionTask *task, NSError *error);
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
typedef void (^AFURLSessionTaskDidFinishCollectingMetricsBlock)(NSURLSession *session, NSURLSessionTask *task, NSURLSessionTaskMetrics * metrics);
#endif

typedef NSURLSessionResponseDisposition (^AFURLSessionDataTaskDidReceiveResponseBlock)(NSURLSession *session, NSURLSessionDataTask *dataTask, NSURLResponse *response);
typedef void (^AFURLSessionDataTaskDidBecomeDownloadTaskBlock)(NSURLSession *session, NSURLSessionDataTask *dataTask, NSURLSessionDownloadTask *downloadTask);
Expand All @@ -122,7 +124,9 @@ - (instancetype)initWithTask:(NSURLSessionTask *)task;
@property (nonatomic, strong) NSProgress *uploadProgress;
@property (nonatomic, strong) NSProgress *downloadProgress;
@property (nonatomic, copy) NSURL *downloadFileURL;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
@property (nonatomic, strong) NSURLSessionTaskMetrics *sessionTaskMetrics;
#endif
@property (nonatomic, copy) AFURLSessionDownloadTaskDidFinishDownloadingBlock downloadTaskDidFinishDownloading;
@property (nonatomic, copy) AFURLSessionTaskProgressBlock uploadProgressBlock;
@property (nonatomic, copy) AFURLSessionTaskProgressBlock downloadProgressBlock;
Expand Down Expand Up @@ -213,7 +217,7 @@ - (void)URLSession:(__unused NSURLSession *)session
self.mutableData = nil;
}

#if AF_CAN_USE_AT_AVAILABLE
#if AF_CAN_USE_AT_AVAILABLE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
if (@available(iOS 10, macOS 10.12, watchOS 3, tvOS 10, *)) {
if (self.sessionTaskMetrics) {
userInfo[AFNetworkingTaskDidCompleteSessionTaskMetrics] = self.sessionTaskMetrics;
Expand Down Expand Up @@ -269,11 +273,13 @@ - (void)URLSession:(__unused NSURLSession *)session
}
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
- (void)URLSession:(NSURLSession *)session
task:(NSURLSessionTask *)task
didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)metrics {
self.sessionTaskMetrics = metrics;
}
#endif

#pragma mark - NSURLSessionDataDelegate

Expand Down Expand Up @@ -889,9 +895,11 @@ - (void)setTaskDidCompleteBlock:(void (^)(NSURLSession *session, NSURLSessionTas
self.taskDidComplete = block;
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
- (void)setTaskDidFinishCollectingMetricsBlock:(void (^)(NSURLSession * _Nonnull, NSURLSessionTask * _Nonnull, NSURLSessionTaskMetrics * _Nullable))block {
self.taskDidFinishCollectingMetrics = block;
}
#endif

#pragma mark -

Expand Down Expand Up @@ -1099,6 +1107,7 @@ - (void)URLSession:(NSURLSession *)session
}
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
- (void)URLSession:(NSURLSession *)session
task:(NSURLSessionTask *)task
didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)metrics
Expand All @@ -1113,6 +1122,7 @@ - (void)URLSession:(NSURLSession *)session
self.taskDidFinishCollectingMetrics(session, task, metrics);
}
}
#endif

#pragma mark - NSURLSessionDataDelegate

Expand Down
2 changes: 2 additions & 0 deletions Tests/Tests/AFURLSessionManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,12 @@ - (void)testSessionTaskDoesReportMetrics {
return YES;
}];

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
__weak XCTestExpectation *metricsBlock = [self expectationWithDescription:@"Metrics completion block is called"];
[self.localManager setTaskDidFinishCollectingMetricsBlock:^(NSURLSession * _Nonnull session, NSURLSessionTask * _Nonnull task, NSURLSessionTaskMetrics * _Nullable metrics) {
[metricsBlock fulfill];
}];
#endif

NSURLSessionTask *task = [self.localManager downloadTaskWithRequest:[self bigImageURLRequest]
progress:nil
Expand Down

0 comments on commit 63410f3

Please sign in to comment.