From 9c07ac0a5645abb58850253eeb109ed0dca515c1 Mon Sep 17 00:00:00 2001 From: Elf Sundae Date: Fri, 27 Mar 2020 08:43:45 +0800 Subject: [PATCH] Fix API availability warnings for NSURLSessionTaskMetrics (#4516) * Fix API availability warnings for NSURLSessionTaskMetrics * Fix API availability warnings for NSURLSessionTaskMetrics --- AFNetworking/AFCompatibilityMacros.h | 10 ++++++++-- AFNetworking/AFURLSessionManager.h | 2 +- AFNetworking/AFURLSessionManager.m | 12 ++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/AFNetworking/AFCompatibilityMacros.h b/AFNetworking/AFCompatibilityMacros.h index cffbde2583..1f0ab26d98 100644 --- a/AFNetworking/AFCompatibilityMacros.h +++ b/AFNetworking/AFCompatibilityMacros.h @@ -22,10 +22,16 @@ #ifndef AFCompatibilityMacros_h #define AFCompatibilityMacros_h +#ifdef API_AVAILABLE + #define AF_API_AVAILABLE(...) API_AVAILABLE(__VA_ARGS__) +#else + #define AF_API_AVAILABLE(...) +#endif // API_AVAILABLE + #ifdef API_UNAVAILABLE - #define AF_API_UNAVAILABLE(x) API_UNAVAILABLE(x) + #define AF_API_UNAVAILABLE(...) API_UNAVAILABLE(__VA_ARGS__) #else - #define AF_API_UNAVAILABLE(x) + #define AF_API_UNAVAILABLE(...) #endif // API_UNAVAILABLE #if __has_warning("-Wunguarded-availability-new") diff --git a/AFNetworking/AFURLSessionManager.h b/AFNetworking/AFURLSessionManager.h index 03a5ed494b..fea4ed84b4 100644 --- a/AFNetworking/AFURLSessionManager.h +++ b/AFNetworking/AFURLSessionManager.h @@ -392,7 +392,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 AF_CAN_INCLUDE_SESSION_TASK_METRICS -- (void)setTaskDidFinishCollectingMetricsBlock:(nullable void (^)(NSURLSession *session, NSURLSessionTask *task, NSURLSessionTaskMetrics * _Nullable metrics))block; +- (void)setTaskDidFinishCollectingMetricsBlock:(nullable void (^)(NSURLSession *session, NSURLSessionTask *task, NSURLSessionTaskMetrics * _Nullable metrics))block AF_API_AVAILABLE(ios(10), macosx(10.12), watchos(3), tvos(10)); #endif ///------------------------------------------- /// @name Setting Data Task Delegate Callbacks diff --git a/AFNetworking/AFURLSessionManager.m b/AFNetworking/AFURLSessionManager.m index 76016750a6..e82f0770dc 100644 --- a/AFNetworking/AFURLSessionManager.m +++ b/AFNetworking/AFURLSessionManager.m @@ -99,7 +99,7 @@ static dispatch_group_t url_session_manager_completion_group() { 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 AF_CAN_INCLUDE_SESSION_TASK_METRICS -typedef void (^AFURLSessionTaskDidFinishCollectingMetricsBlock)(NSURLSession *session, NSURLSessionTask *task, NSURLSessionTaskMetrics * metrics); +typedef void (^AFURLSessionTaskDidFinishCollectingMetricsBlock)(NSURLSession *session, NSURLSessionTask *task, NSURLSessionTaskMetrics * metrics) AF_API_AVAILABLE(ios(10), macosx(10.12), watchos(3), tvos(10)); #endif typedef NSURLSessionResponseDisposition (^AFURLSessionDataTaskDidReceiveResponseBlock)(NSURLSession *session, NSURLSessionDataTask *dataTask, NSURLResponse *response); @@ -125,7 +125,7 @@ - (instancetype)initWithTask:(NSURLSessionTask *)task; @property (nonatomic, strong) NSProgress *downloadProgress; @property (nonatomic, copy) NSURL *downloadFileURL; #if AF_CAN_INCLUDE_SESSION_TASK_METRICS -@property (nonatomic, strong) NSURLSessionTaskMetrics *sessionTaskMetrics; +@property (nonatomic, strong) NSURLSessionTaskMetrics *sessionTaskMetrics AF_API_AVAILABLE(ios(10), macosx(10.12), watchos(3), tvos(10)); #endif @property (nonatomic, copy) AFURLSessionDownloadTaskDidFinishDownloadingBlock downloadTaskDidFinishDownloading; @property (nonatomic, copy) AFURLSessionTaskProgressBlock uploadProgressBlock; @@ -276,7 +276,7 @@ - (void)URLSession:(__unused NSURLSession *)session #if AF_CAN_INCLUDE_SESSION_TASK_METRICS - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task -didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)metrics { +didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)metrics AF_API_AVAILABLE(ios(10), macosx(10.12), watchos(3), tvos(10)) { self.sessionTaskMetrics = metrics; } #endif @@ -486,7 +486,7 @@ @interface AFURLSessionManager () @property (readwrite, nonatomic, copy) AFURLSessionTaskDidSendBodyDataBlock taskDidSendBodyData; @property (readwrite, nonatomic, copy) AFURLSessionTaskDidCompleteBlock taskDidComplete; #if AF_CAN_INCLUDE_SESSION_TASK_METRICS -@property (readwrite, nonatomic, copy) AFURLSessionTaskDidFinishCollectingMetricsBlock taskDidFinishCollectingMetrics; +@property (readwrite, nonatomic, copy) AFURLSessionTaskDidFinishCollectingMetricsBlock taskDidFinishCollectingMetrics AF_API_AVAILABLE(ios(10), macosx(10.12), watchos(3), tvos(10)); #endif @property (readwrite, nonatomic, copy) AFURLSessionDataTaskDidReceiveResponseBlock dataTaskDidReceiveResponse; @property (readwrite, nonatomic, copy) AFURLSessionDataTaskDidBecomeDownloadTaskBlock dataTaskDidBecomeDownloadTask; @@ -916,7 +916,7 @@ - (void)setTaskDidCompleteBlock:(void (^)(NSURLSession *session, NSURLSessionTas } #if AF_CAN_INCLUDE_SESSION_TASK_METRICS -- (void)setTaskDidFinishCollectingMetricsBlock:(void (^)(NSURLSession * _Nonnull, NSURLSessionTask * _Nonnull, NSURLSessionTaskMetrics * _Nullable))block { +- (void)setTaskDidFinishCollectingMetricsBlock:(void (^)(NSURLSession * _Nonnull, NSURLSessionTask * _Nonnull, NSURLSessionTaskMetrics * _Nullable))block AF_API_AVAILABLE(ios(10), macosx(10.12), watchos(3), tvos(10)) { self.taskDidFinishCollectingMetrics = block; } #endif @@ -1130,7 +1130,7 @@ - (void)URLSession:(NSURLSession *)session #if AF_CAN_INCLUDE_SESSION_TASK_METRICS - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task -didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)metrics +didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)metrics AF_API_AVAILABLE(ios(10), macosx(10.12), watchos(3), tvos(10)) { AFURLSessionManagerTaskDelegate *delegate = [self delegateForTask:task]; // Metrics may fire after URLSession:task:didCompleteWithError: is called, delegate may be nil