Переглянути джерело

Adding documentation to UIProgressView category

Mattt Thompson 12 роки тому
батько
коміт
813ea16a26

+ 34 - 6
UIKit+AFNetworking/UIProgressView+AFNetworking.h

@@ -20,41 +20,69 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
+#import <Foundation/Foundation.h>
+
+#import <Availability.h>
+
+#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
+
 #import <UIKit/UIKit.h>
 
 @class AFURLConnectionOperation;
 
 /**
- 
+ This category adds methods to the UIKit framework's `UIProgressView` class. The methods in this category provide support for binding the progress to the upload and download progress of a session task or request operation.
  */
 @interface UIProgressView (AFNetworking)
 
-///
+///------------------------------------
+/// @name Setting Session Task Progress
+///------------------------------------
 
 /**
+ Binds the progress to the upload progress of the specified session task.
  
+ @param task The session task.
+ @param animated `YES` if the change should be animated, `NO` if the change should happen immediately.
  */
+#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000) || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
 - (void)setProgressWithUploadProgressOfTask:(NSURLSessionUploadTask *)task
                                    animated:(BOOL)animated;
+#endif
 
 /**
- 
+ Binds the progress to the download progress of the specified session task.
+
+ @param task The session task.
+ @param animated `YES` if the change should be animated, `NO` if the change should happen immediately.
  */
+#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000) || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
 - (void)setProgressWithDownloadProgressOfTask:(NSURLSessionDownloadTask *)task
                                      animated:(BOOL)animated;
+#endif
 
-///
+///------------------------------------
+/// @name Setting Session Task Progress
+///------------------------------------
 
 /**
- 
+ Binds the progress to the upload progress of the specified request operation.
+
+ @param operation The request operation.
+ @param animated `YES` if the change should be animated, `NO` if the change should happen immediately.
  */
 - (void)setProgressWithUploadProgressOfOperation:(AFURLConnectionOperation *)operation
                                         animated:(BOOL)animated;
 
 /**
- 
+ Binds the progress to the download progress of the specified request operation.
+
+ @param operation The request operation.
+ @param animated `YES` if the change should be animated, `NO` if the change should happen immediately.
  */
 - (void)setProgressWithDownloadProgressOfOperation:(AFURLConnectionOperation *)operation
                                           animated:(BOOL)animated;
 
 @end
+
+#endif

+ 21 - 3
UIKit+AFNetworking/UIProgressView+AFNetworking.m

@@ -22,9 +22,15 @@
 
 #import "UIProgressView+AFNetworking.h"
 
+#import <objc/runtime.h>
+
+#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
+
 #import "AFURLConnectionOperation.h"
 
-#import <objc/runtime.h>
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
+#import "AFURLSessionManager.h"
+#endif
 
 static void * AFTaskCountOfBytesSentContext = &AFTaskCountOfBytesSentContext;
 static void * AFTaskCountOfBytesReceivedContext = &AFTaskCountOfBytesReceivedContext;
@@ -70,6 +76,8 @@ static char kAFDownloadProgressAnimated;
 
 #pragma mark -
 
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
+
 - (void)setProgressWithUploadProgressOfTask:(NSURLSessionUploadTask *)task
                                    animated:(BOOL)animated
 {
@@ -88,6 +96,8 @@ static char kAFDownloadProgressAnimated;
     [self af_setDownloadProgressAnimated:animated];
 }
 
+#endif
+
 #pragma mark -
 
 - (void)setProgressWithUploadProgressOfOperation:(AFURLConnectionOperation *)operation
@@ -140,13 +150,18 @@ static char kAFDownloadProgressAnimated;
                     [self setProgress:[object countOfBytesSent] / ([object countOfBytesExpectedToSend] * 1.0f) animated:self.af_uploadProgressAnimated];
                 });
             }
-        } else if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesReceived))]) {
+        }
+
+        if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesReceived))]) {
             if ([object countOfBytesExpectedToReceive] > 0) {
                 dispatch_async(dispatch_get_main_queue(), ^{
                     [self setProgress:[object countOfBytesReceived] / ([object countOfBytesExpectedToReceive] * 1.0f) animated:self.af_downloadProgressAnimated];
                 });
             }
-        } else if ([keyPath isEqualToString:NSStringFromSelector(@selector(state))]) {
+        }
+
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
+        if ([keyPath isEqualToString:NSStringFromSelector(@selector(state))]) {
             if ([(NSURLSessionTask *)object state] == NSURLSessionTaskStateCompleted) {
                 @try {
                     [object removeObserver:self forKeyPath:NSStringFromSelector(@selector(state))];
@@ -163,6 +178,9 @@ static char kAFDownloadProgressAnimated;
             }
         }
     }
+#endif
 }
 
 @end
+
+#endif