|
@@ -22,46 +22,59 @@
|
|
|
|
|
|
#import "UIActivityIndicatorView+AFNetworking.h"
|
|
#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"
|
|
#import "AFURLSessionManager.h"
|
|
|
|
+#endif
|
|
|
|
|
|
@implementation UIActivityIndicatorView (AFNetworking)
|
|
@implementation UIActivityIndicatorView (AFNetworking)
|
|
|
|
|
|
-- (void)setAnimatingWithStateOfOperation:(AFURLConnectionOperation *)operation {
|
|
|
|
|
|
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
|
|
|
|
+- (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task {
|
|
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
|
|
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];
|
|
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
|
|
@end
|
|
|
|
+
|
|
|
|
+#endif
|