Skip to content

Commit

Permalink
Replaced preprocessor variable to make sure all valid targets allow N…
Browse files Browse the repository at this point in the history
…SURLSessionTaskMetrics
  • Loading branch information
Caelin Jackson-King committed Jun 29, 2018
1 parent 6622b05 commit 54f1135
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
6 changes: 6 additions & 0 deletions AFNetworking/AFCompatibilityMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@
#define AF_CAN_USE_AT_AVAILABLE 0
#endif

#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 || __MAC_OS_VERSION_MAX_ALLOWED >= __MAC_OS_10_12 || __WATCH_OS_MAX_VERSION_ALLOWED >= __WATCH_OS_3_0 || __TV_OS_MAX_VERSION_ALLOWED >= __TV_OS_10_0)
#define AF_CAN_INCLUDE_SESSION_TASK_METRICS 1
#else
#define AF_CAN_INCLUDE_SESSION_TASK_METRICS 0
#endif

#endif /* AFCompatibilityMacros_h */
2 changes: 1 addition & 1 deletion AFNetworking/AFURLSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ 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
#if AF_CAN_INCLUDE_SESSION_TASK_METRICS
- (void)setTaskDidFinishCollectingMetricsBlock:(nullable void (^)(NSURLSession *session, NSURLSessionTask *task, NSURLSessionTaskMetrics * _Nullable metrics))block;
#endif
///-------------------------------------------
Expand Down
14 changes: 7 additions & 7 deletions AFNetworking/AFURLSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ 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
#if AF_CAN_INCLUDE_SESSION_TASK_METRICS
typedef void (^AFURLSessionTaskDidFinishCollectingMetricsBlock)(NSURLSession *session, NSURLSessionTask *task, NSURLSessionTaskMetrics * metrics);
#endif

Expand All @@ -124,7 +124,7 @@ - (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
#if AF_CAN_INCLUDE_SESSION_TASK_METRICS
@property (nonatomic, strong) NSURLSessionTaskMetrics *sessionTaskMetrics;
#endif
@property (nonatomic, copy) AFURLSessionDownloadTaskDidFinishDownloadingBlock downloadTaskDidFinishDownloading;
Expand Down Expand Up @@ -217,7 +217,7 @@ - (void)URLSession:(__unused NSURLSession *)session
self.mutableData = nil;
}

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

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
#if AF_CAN_INCLUDE_SESSION_TASK_METRICS
- (void)URLSession:(NSURLSession *)session
task:(NSURLSessionTask *)task
didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)metrics {
Expand Down Expand Up @@ -485,7 +485,7 @@ @interface AFURLSessionManager ()
@property (readwrite, nonatomic, copy) AFURLSessionTaskNeedNewBodyStreamBlock taskNeedNewBodyStream;
@property (readwrite, nonatomic, copy) AFURLSessionTaskDidSendBodyDataBlock taskDidSendBodyData;
@property (readwrite, nonatomic, copy) AFURLSessionTaskDidCompleteBlock taskDidComplete;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
#if AF_CAN_INCLUDE_SESSION_TASK_METRICS
@property (readwrite, nonatomic, copy) AFURLSessionTaskDidFinishCollectingMetricsBlock taskDidFinishCollectingMetrics;
#endif
@property (readwrite, nonatomic, copy) AFURLSessionDataTaskDidReceiveResponseBlock dataTaskDidReceiveResponse;
Expand Down Expand Up @@ -897,7 +897,7 @@ - (void)setTaskDidCompleteBlock:(void (^)(NSURLSession *session, NSURLSessionTas
self.taskDidComplete = block;
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
#if AF_CAN_INCLUDE_SESSION_TASK_METRICS
- (void)setTaskDidFinishCollectingMetricsBlock:(void (^)(NSURLSession * _Nonnull, NSURLSessionTask * _Nonnull, NSURLSessionTaskMetrics * _Nullable))block {
self.taskDidFinishCollectingMetrics = block;
}
Expand Down Expand Up @@ -1109,7 +1109,7 @@ - (void)URLSession:(NSURLSession *)session
}
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
#if AF_CAN_INCLUDE_SESSION_TASK_METRICS
- (void)URLSession:(NSURLSession *)session
task:(NSURLSessionTask *)task
didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)metrics
Expand Down
2 changes: 1 addition & 1 deletion Tests/Tests/AFURLSessionManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ - (void)testSessionTaskDoesReportMetrics {
return YES;
}];

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

0 comments on commit 54f1135

Please sign in to comment.