Browse Source

Adding documentation for UIActivityIndicatorView category

Mattt Thompson 12 years ago
parent
commit
a02f52b3b9

+ 26 - 5
UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.h

@@ -20,25 +20,46 @@
 // 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 `UIActivityIndicatorView` class. The methods in this category provide support for automatically starting and stopping animation depending on the loading state of a request operation or session task.
  */
 @interface UIActivityIndicatorView (AFNetworking)
 
+///----------------------------------
+/// @name Animating for Session Tasks
+///----------------------------------
+
 /**
- 
+ Binds the animating state to the state of the specified task.
+
+ @param task The task. If `nil`, automatic updating from any previously specified operation will be disabled.
  */
-- (void)setAnimatingWithStateOfOperation:(AFURLConnectionOperation *)operation;
+#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)setAnimatingWithStateOfTask:(NSURLSessionTask *)task;
+#endif
 
-///
+///---------------------------------------
+/// @name Animating for Request Operations
+///---------------------------------------
 
 /**
+ Binds the animating state to the execution state of the specified operation.
  
+ @param operation The operation. If `nil`, automatic updating from any previously specified operation will be disabled.
  */
-- (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task;
+- (void)setAnimatingWithStateOfOperation:(AFURLConnectionOperation *)operation;
 
 @end
+
+#endif

+ 40 - 25
UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.m

@@ -22,46 +22,59 @@
 
 #import "UIActivityIndicatorView+AFNetworking.h"
 
-#import "AFURLConnectionOperation.h"
+#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
+
+#import "AFHTTPRequestOperation.h"
+
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
 #import "AFURLSessionManager.h"
+#endif
 
 @implementation UIActivityIndicatorView (AFNetworking)
 
-- (void)setAnimatingWithStateOfOperation:(AFURLConnectionOperation *)operation {
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
+- (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task {
     NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
 
-    [notificationCenter removeObserver:self name:AFNetworkingOperationDidStartNotification object:nil];
-    [notificationCenter removeObserver:self name:AFNetworkingOperationDidFinishNotification object:nil];
+    [notificationCenter removeObserver:self name:AFNetworkingTaskDidStartNotification object:nil];
+    [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil];
+    [notificationCenter removeObserver:self name:AFNetworkingTaskDidFinishNotification object:nil];
 
-    if (![operation isFinished]) {
-        if ([operation isExecuting]) {
-            [self startAnimating];
-        } else {
-            [self stopAnimating];
-        }
+    if (task) {
+        if (task.state != NSURLSessionTaskStateCompleted) {
+            if (task.state == NSURLSessionTaskStateRunning) {
+                [self startAnimating];
+            } else {
+                [self stopAnimating];
+            }
 
-        [notificationCenter addObserver:self selector:@selector(af_startAnimating) name:AFNetworkingOperationDidStartNotification object:operation];
-        [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingOperationDidFinishNotification object:operation];
+            [notificationCenter addObserver:self selector:@selector(af_startAnimating) name:AFNetworkingTaskDidStartNotification object:task];
+            [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingTaskDidFinishNotification object:task];
+            [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingTaskDidSuspendNotification object:task];
+        }
     }
 }
+#endif
 
-- (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task {
+#pragma mark -
+
+- (void)setAnimatingWithStateOfOperation:(AFURLConnectionOperation *)operation {
     NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
 
-    [notificationCenter removeObserver:self name:AFNetworkingTaskDidStartNotification object:nil];
-    [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil];
-    [notificationCenter removeObserver:self name:AFNetworkingTaskDidFinishNotification object:nil];
+    [notificationCenter removeObserver:self name:AFNetworkingOperationDidStartNotification object:nil];
+    [notificationCenter removeObserver:self name:AFNetworkingOperationDidFinishNotification object:nil];
 
-    if (task.state != NSURLSessionTaskStateCompleted) {
-        if (task.state == NSURLSessionTaskStateRunning) {
-            [self startAnimating];
-        } else {
-            [self stopAnimating];
-        }
+    if (operation) {
+        if (![operation isFinished]) {
+            if ([operation isExecuting]) {
+                [self startAnimating];
+            } else {
+                [self stopAnimating];
+            }
 
-        [notificationCenter addObserver:self selector:@selector(af_startAnimating) name:AFNetworkingTaskDidStartNotification object:task];
-        [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingTaskDidFinishNotification object:task];
-        [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingTaskDidSuspendNotification object:task];
+            [notificationCenter addObserver:self selector:@selector(af_startAnimating) name:AFNetworkingOperationDidStartNotification object:operation];
+            [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingOperationDidFinishNotification object:operation];
+        }
     }
 }
 
@@ -80,3 +93,5 @@
 }
 
 @end
+
+#endif