Created
September 19, 2012 00:29
-
-
Save cbowns/3746934 to your computer and use it in GitHub Desktop.
UIApplication+NetworkActivity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIApplication+NetworkActivity.h | |
// | |
// Created by Christopher Bowns on 4/11/12. | |
// Original implementation: http://stackoverflow.com/a/6978817/774 | |
// Copyright (c) 2012 Mechanical Pants Software | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIApplication (NetworkActivity) | |
- (void)showNetworkActivityIndicator; | |
- (void)hideNetworkActivityIndicator; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIApplication+NetworkActivity.m | |
// | |
// Created by Christopher Bowns on 4/11/12. | |
// Original implementation: http://stackoverflow.com/a/6978817/774 | |
// Copyright (c) 2012 Mechanical Pants Software | |
// | |
#import "UIApplication+NetworkActivity.h" | |
static NSInteger activityCount = 0; | |
@implementation UIApplication (NetworkActivity) | |
- (void)showNetworkActivityIndicator { | |
@synchronized ([UIApplication sharedApplication]) { | |
if (activityCount == 0) { | |
[self setNetworkActivityIndicatorVisible:YES]; | |
} | |
activityCount++; | |
} | |
} | |
- (void)hideNetworkActivityIndicator { | |
@synchronized ([UIApplication sharedApplication]) { | |
activityCount--; | |
if (activityCount <= 0) { | |
[self setNetworkActivityIndicatorVisible:NO]; | |
} | |
if (activityCount < 0) { | |
NSLog(@"%s fell to a negative activityCount!", __func__); | |
activityCount = 0; | |
} | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment