Adding documentation for AFNetworkActivityIndicatorManager

Changing public API for AFNetworkActivityIndicatorManager from -start/stopAnimating to -increment/decrementActivityCount
This commit is contained in:
Mattt Thompson 2011-09-22 10:25:55 -05:00
parent 95ca172d9d
commit c84ca99269
3 changed files with 21 additions and 6 deletions

View file

@ -227,11 +227,11 @@ static NSThread *_networkRequestThread = nil;
switch (state) {
case AFHTTPOperationExecutingState:
[[AFNetworkActivityIndicatorManager sharedManager] startAnimating];
[[AFNetworkActivityIndicatorManager sharedManager] incrementActivityCount];
[[NSNotificationCenter defaultCenter] postNotificationName:AFHTTPOperationDidStartNotification object:self];
break;
case AFHTTPOperationFinishedState:
[[AFNetworkActivityIndicatorManager sharedManager] stopAnimating];
[[AFNetworkActivityIndicatorManager sharedManager] decrementActivityCount];
[[NSNotificationCenter defaultCenter] postNotificationName:AFHTTPOperationDidFinishNotification object:self];
break;
default:

View file

@ -22,14 +22,29 @@
#import <Foundation/Foundation.h>
/**
`AFNetworkActivityIndicatorManager` manages the state of the network activity indicator in the status bar. When network operations start, they can call `-incrementActivityCount`, and once they're finished, call `-decrementActivityCount`. The number of active requests is incremented and decremented much like a stack or a semaphore, and the activity indicator will animate so long as that number is greater than zero.
*/
@interface AFNetworkActivityIndicatorManager : NSObject {
@private
NSInteger _activityCount;
}
/**
Returns the shared network activity indicator manager object for the system.
@return The systemwide network activity indicator manager.
*/
+ (AFNetworkActivityIndicatorManager *)sharedManager;
- (void)startAnimating;
- (void)stopAnimating;
/**
Increments the number of active network requests. If this number was zero before incrementing, this will start animating the status bar network activity indicator.
*/
- (void)incrementActivityCount;
/**
Decrements the number of active network requests. If this number becomes zero before decrementing, this will stop animating the status bar network activity indicator.
*/
- (void)decrementActivityCount;
@end

View file

@ -47,13 +47,13 @@
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:self.activityCount > 0];
}
- (void)startAnimating {
- (void)incrementActivityCount {
@synchronized(self) {
self.activityCount += 1;
}
}
- (void)stopAnimating {
- (void)decrementActivityCount {
@synchronized(self) {
self.activityCount -= 1;
}