Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UIApplication+NetworkActivity
//
// 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
//
// 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
You can’t perform that action at this time.