Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I wrote a singleton that solves the problem of multiple connections by keeping a counter of what is happening (to avoid removing the status when a connection returns but another one is still active):</p> <p>The header file:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface RMActivityIndicator : NSObject -(void)increaseActivity; -(void)decreaseActivity; -(void)noActivity; +(RMActivityIndicator *)sharedManager; @end </code></pre> <p>and implementation:</p> <pre><code>#import "RMActivityIndicator.h" @interface RMActivityIndicator () @property(nonatomic,assign) unsigned int activityCounter; @end @implementation RMActivityIndicator - (id)init { self = [super init]; if (self) { self.activityCounter = 0; } return self; } -(void)increaseActivity{ @synchronized(self) { self.activityCounter++; } [self updateActivity]; } -(void)decreaseActivity{ @synchronized(self) { if (self.activityCounter&gt;0) self.activityCounter--; } [self updateActivity]; } -(void)noActivity{ self.activityCounter = 0; [self updateActivity]; } -(void)updateActivity{ UIApplication* app = [UIApplication sharedApplication]; app.networkActivityIndicatorVisible = (self.activityCounter&gt;0); } #pragma mark - #pragma mark Singleton instance +(RMActivityIndicator *)sharedManager { static dispatch_once_t pred; static RMActivityIndicator *shared = nil; dispatch_once(&amp;pred, ^{ shared = [[RMActivityIndicator alloc] init]; }); return shared; } @end </code></pre> <p>Example:</p> <pre><code> [[RMActivityIndicator sharedManager]increaseActivity]; [NSURLConnection sendAsynchronousRequest:urlRequest queue:self.networkReceiveProcessQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [[RMActivityIndicator sharedManager]decreaseActivity]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload