Adding documentation for AFNetworkActivityIndicatorManager
Changing public API for AFNetworkActivityIndicatorManager from -start/stopAnimating to -increment/decrementActivityCount
This commit is contained in:
parent
95ca172d9d
commit
c84ca99269
3 changed files with 21 additions and 6 deletions
|
|
@ -227,11 +227,11 @@ static NSThread *_networkRequestThread = nil;
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case AFHTTPOperationExecutingState:
|
case AFHTTPOperationExecutingState:
|
||||||
[[AFNetworkActivityIndicatorManager sharedManager] startAnimating];
|
[[AFNetworkActivityIndicatorManager sharedManager] incrementActivityCount];
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:AFHTTPOperationDidStartNotification object:self];
|
[[NSNotificationCenter defaultCenter] postNotificationName:AFHTTPOperationDidStartNotification object:self];
|
||||||
break;
|
break;
|
||||||
case AFHTTPOperationFinishedState:
|
case AFHTTPOperationFinishedState:
|
||||||
[[AFNetworkActivityIndicatorManager sharedManager] stopAnimating];
|
[[AFNetworkActivityIndicatorManager sharedManager] decrementActivityCount];
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:AFHTTPOperationDidFinishNotification object:self];
|
[[NSNotificationCenter defaultCenter] postNotificationName:AFHTTPOperationDidFinishNotification object:self];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,29 @@
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#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 {
|
@interface AFNetworkActivityIndicatorManager : NSObject {
|
||||||
@private
|
@private
|
||||||
NSInteger _activityCount;
|
NSInteger _activityCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the shared network activity indicator manager object for the system.
|
||||||
|
|
||||||
|
@return The systemwide network activity indicator manager.
|
||||||
|
*/
|
||||||
+ (AFNetworkActivityIndicatorManager *)sharedManager;
|
+ (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
|
@end
|
||||||
|
|
|
||||||
|
|
@ -47,13 +47,13 @@
|
||||||
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:self.activityCount > 0];
|
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:self.activityCount > 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)startAnimating {
|
- (void)incrementActivityCount {
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
self.activityCount += 1;
|
self.activityCount += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)stopAnimating {
|
- (void)decrementActivityCount {
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
self.activityCount -= 1;
|
self.activityCount -= 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue