diff --git a/AFNetworking/AFURLSessionManager.h b/AFNetworking/AFURLSessionManager.h index 99e167a54b..816c02d9aa 100644 --- a/AFNetworking/AFURLSessionManager.h +++ b/AFNetworking/AFURLSessionManager.h @@ -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 ///------------------------------------------- diff --git a/AFNetworking/AFURLSessionManager.m b/AFNetworking/AFURLSessionManager.m index cd0fdf7f97..6669b3c0be 100644 --- a/AFNetworking/AFURLSessionManager.m +++ b/AFNetworking/AFURLSessionManager.m @@ -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); @@ -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; @@ -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; @@ -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 @@ -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 - @@ -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 @@ -1113,6 +1122,7 @@ - (void)URLSession:(NSURLSession *)session self.taskDidFinishCollectingMetrics(session, task, metrics); } } +#endif #pragma mark - NSURLSessionDataDelegate diff --git a/Tests/Tests/AFURLSessionManagerTests.m b/Tests/Tests/AFURLSessionManagerTests.m index deb067dfe2..b34e5c0745 100644 --- a/Tests/Tests/AFURLSessionManagerTests.m +++ b/Tests/Tests/AFURLSessionManagerTests.m @@ -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