Wednesday, May 22, 2013

UIApplication networkActivityIndicatorVisible example ios


[UIApplication networkActivityIndicatorVisible]

A Boolean value that turns an indicator of network activity on or off.
@property(nonatomic, getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible
Discussion of [UIApplication networkActivityIndicatorVisible]
Specify YES if the application should show network activity and NO if it should not. The default value is NO. A spinning indicator in the status bar shows network activity. The application may explicitly hide or show this indicator.
Example of [UIApplication networkActivityIndicatorVisible]
- (void)showNetworkActivityIndicator {
    if ([[UIApplication sharedApplication] isStatusBarHidden]) return;
    @synchronized ([UIApplication sharedApplication]) {
        if (activityCount == 0) {
            self.networkActivityIndicatorVisible = YES;
        }
        activityCount++;
    }
}
Example of [UIApplication networkActivityIndicatorVisible]
- (void)hideNetworkActivityIndicator {
    if ([[UIApplication sharedApplication] isStatusBarHidden]) return;
    @synchronized ([UIApplication sharedApplication]) {
        activityCount--;
        if (activityCount <= 0) {
            self.networkActivityIndicatorVisible = NO;
            activityCount=0;
        }    
    }
}
Example of [UIApplication networkActivityIndicatorVisible]
- (void) doActualWork {
  [self downloadFunction];
  [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

- (void) doWork {
  [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
  [self performSelector:@selector(doActualWork) withObject:Nil afterDelay:0.05];
}