RASingleton.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // Singleton.m
  3. // iSales-NPD
  4. //
  5. // Created by Jack on 2016/10/12.
  6. // Copyright © 2016年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RASingleton.h"
  9. #import "NotificationNameCenter.h"
  10. @interface RASingleton ()
  11. @property (nonatomic,strong) NSMutableDictionary *globalParameters;
  12. @end
  13. @implementation RASingleton
  14. #pragma mark - Global Parameter
  15. - (NSMutableDictionary *)globalParameters {
  16. if (!_globalParameters) {
  17. _globalParameters = [NSMutableDictionary dictionary];
  18. }
  19. return _globalParameters;
  20. }
  21. - (void)setGlobalParameter:(id)param forKey:(NSString *)key {
  22. if (param == nil || key == nil) {
  23. return;
  24. }
  25. [self.globalParameters setObject:param forKey:key];
  26. }
  27. - (id)globalParameterForKey:(NSString *)key {
  28. if (key == nil) {
  29. return nil;
  30. }
  31. return [self.globalParameters objectForKey:key];
  32. }
  33. - (void)dealloc {
  34. [[NSNotificationCenter defaultCenter] removeObserver:self];
  35. }
  36. + (instancetype)sharedInstance {
  37. static RASingleton *singleton = nil;
  38. static dispatch_once_t onceToken;
  39. dispatch_once(&onceToken, ^{
  40. singleton = [[RASingleton alloc] init];
  41. [[NSNotificationCenter defaultCenter] addObserver:singleton selector:@selector(handleLogin:) name:User_LoginOK_Notification object:nil];
  42. });
  43. return singleton;
  44. }
  45. - (void)setGlobal_lock:(BOOL)global_lock {
  46. _global_lock = global_lock;
  47. if (global_lock) {
  48. [[NSNotificationCenter defaultCenter] postNotificationName:Lock_Permission_Notification object:nil];
  49. } else {
  50. [[NSNotificationCenter defaultCenter] postNotificationName:unLock_Permission_Notification object:nil];
  51. }
  52. }
  53. - (void)resetGlobalLock {
  54. _global_lock = NO;
  55. }
  56. - (void)handleLogin:(NSNotification *)notification {
  57. self.currentOrderIsMerged = NO;
  58. }
  59. - (NSString *)homeClickedItemName {
  60. if (!_homeClickedItemName) {
  61. _homeClickedItemName = @"";
  62. }
  63. return _homeClickedItemName;
  64. }
  65. - (NSString *)deliveryString {
  66. if (!_deliveryString) {
  67. _deliveryString = @"";
  68. }
  69. return _deliveryString;
  70. }
  71. @end