Skip to content

Instantly share code, notes, and snippets.

@cbowns
Created September 19, 2012 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbowns/3746934 to your computer and use it in GitHub Desktop.
Save cbowns/3746934 to your computer and use it in GitHub Desktop.
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