Skip to content

Commit

Permalink
Update for changes in AFNetworking's UIKit support
Browse files Browse the repository at this point in the history
  • Loading branch information
mrackwitz committed Dec 29, 2015
1 parent defb640 commit 0f61e54
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/Support/AFNetworking/MRActivityIndicatorView+AFNetworking.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,36 @@
// THE SOFTWARE.

#import "MRActivityIndicatorView+AFNetworking.h"
#import "MRMethodCopier.h"
#import <objc/runtime.h>

#pragma clang diagnostic ignored "-Wincomplete-implementation"
@interface AFActivityIndicatorViewNotificationObserver : NSObject
@property (readonly, nonatomic, weak) UIActivityIndicatorView *activityIndicatorView;
- (instancetype)initWithActivityIndicatorView:(UIActivityIndicatorView *)activityIndicatorView;

@implementation MRActivityIndicatorView (AFNetworking)

+ (void)load {
MRMethodCopier *copier = [MRMethodCopier copierFromClass:UIActivityIndicatorView.class toClass:self];

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
[copier copyInstanceMethod:@selector(setAnimatingWithStateOfTask:)];
- (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task;
#endif

[copier copyInstanceMethod:@selector(setAnimatingWithStateOfOperation:)];

// Internal methods
[copier copyInstanceMethod:NSSelectorFromString(@"af_startAnimating")];
[copier copyInstanceMethod:NSSelectorFromString(@"af_stopAnimating")];
- (void)setAnimatingWithStateOfOperation:(AFURLConnectionOperation *)operation;

@end

@implementation MRActivityIndicatorView (AFNetworking)

- (AFActivityIndicatorViewNotificationObserver *)af_notificationObserver {
AFActivityIndicatorViewNotificationObserver *notificationObserver = objc_getAssociatedObject(self, @selector(af_notificationObserver));
if (notificationObserver == nil) {
notificationObserver = [[AFActivityIndicatorViewNotificationObserver alloc] initWithActivityIndicatorView:(UIActivityIndicatorView *)self];
objc_setAssociatedObject(self, @selector(af_notificationObserver), notificationObserver, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return notificationObserver;
}

- (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task {
[[self af_notificationObserver] setAnimatingWithStateOfTask:task];
}

- (void)setAnimatingWithStateOfOperation:(AFURLConnectionOperation *)operation {
[[self af_notificationObserver] setAnimatingWithStateOfOperation:operation];
}

@end

0 comments on commit 0f61e54

Please sign in to comment.