Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

SDNetworkActivityIndicator.m 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * This file is part of the SDNetworkActivityIndicator package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import "SDNetworkActivityIndicator.h"
  9. @interface SDNetworkActivityIndicator()
  10. {
  11. @private NSUInteger counter;
  12. }
  13. @end
  14. @implementation SDNetworkActivityIndicator
  15. + (instancetype) sharedActivityIndicator
  16. {
  17. static id _sharedInstance = nil;
  18. static dispatch_once_t onceToken;
  19. dispatch_once(&onceToken, ^{
  20. _sharedInstance = [[self alloc] init];
  21. });
  22. return _sharedInstance;
  23. }
  24. - (id)init
  25. {
  26. if ((self = [super init]))
  27. {
  28. counter = 0;
  29. }
  30. return self;
  31. }
  32. - (void)startActivity
  33. {
  34. @synchronized(self)
  35. {
  36. counter++;
  37. [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
  38. }
  39. }
  40. - (void)stopActivity
  41. {
  42. @synchronized(self)
  43. {
  44. if (counter > 0 && --counter == 0)
  45. {
  46. [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
  47. }
  48. }
  49. }
  50. - (void)stopAllActivity
  51. {
  52. @synchronized(self)
  53. {
  54. counter = 0;
  55. [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
  56. }
  57. }
  58. @end