RASingleton.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #import "AppDelegate.h"
  11. #import "RAUtils.h"
  12. @interface RASingleton ()
  13. @property (nonatomic,strong) NSMutableDictionary *globalParameters;
  14. @end
  15. @implementation RASingleton
  16. #pragma mark - Global Parameter
  17. - (NSMutableDictionary *)globalParameters {
  18. if (!_globalParameters) {
  19. _globalParameters = [NSMutableDictionary dictionary];
  20. }
  21. return _globalParameters;
  22. }
  23. - (void)setGlobalParameter:(id)param forKey:(NSString *)key {
  24. if (param == nil || key == nil) {
  25. return;
  26. }
  27. [self.globalParameters setObject:param forKey:key];
  28. }
  29. - (id)globalParameterForKey:(NSString *)key {
  30. if (key == nil) {
  31. return nil;
  32. }
  33. return [self.globalParameters objectForKey:key];
  34. }
  35. - (void)dealloc {
  36. [[NSNotificationCenter defaultCenter] removeObserver:self];
  37. [self removeObserver:self forKeyPath:@"stack_contents"];
  38. }
  39. //- (instancetype)init {
  40. // if (self = [super init]) {
  41. //
  42. // [self addObserver:self forKeyPath:@"scan_cart"
  43. // options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
  44. // context:@"content changed"];
  45. //
  46. // }
  47. // return self;
  48. //}
  49. + (instancetype)sharedInstance {
  50. static RASingleton *singleton = nil;
  51. static dispatch_once_t onceToken;
  52. dispatch_once(&onceToken, ^{
  53. singleton = [[RASingleton alloc] init];
  54. [[NSNotificationCenter defaultCenter] addObserver:singleton selector:@selector(handleLogin:) name:User_LoginOK_Notification object:nil];
  55. // self addObserver:self forKeyPath:self.scan_cart options:<#(NSKeyValueObservingOptions)#> context:<#(nullable void *)#>
  56. });
  57. return singleton;
  58. }
  59. //- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  60. //{
  61. // if(self.enable_OfflineOrder)
  62. // {
  63. // if([keyPath isEqualToString:@"scan_cart"])
  64. // {
  65. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  66. // NSString *documents = [paths objectAtIndex:0];
  67. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  68. //
  69. //
  70. // NSString *orderdir = [documents stringByAppendingPathComponent:appDelegate.order_code];
  71. //
  72. // NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
  73. //
  74. //
  75. //
  76. // [RAUtils dicttofile:cartpath dict:self.scan_cart];
  77. //
  78. //
  79. // self.scan_cart addObserver:<#(nonnull NSObject *)#> forKeyPath:<#(nonnull NSString *)#> options:<#(NSKeyValueObservingOptions)#> context:<#(nullable void *)#>
  80. //
  81. // }
  82. // }
  83. //
  84. //}
  85. - (void)setGlobal_lock:(BOOL)global_lock {
  86. _global_lock = global_lock;
  87. if (global_lock) {
  88. [[NSNotificationCenter defaultCenter] postNotificationName:Lock_Permission_Notification object:nil];
  89. } else {
  90. [[NSNotificationCenter defaultCenter] postNotificationName:unLock_Permission_Notification object:nil];
  91. }
  92. }
  93. - (void)resetGlobalLock {
  94. _global_lock = NO;
  95. }
  96. - (void)handleLogin:(NSNotification *)notification {
  97. self.currentOrderIsMerged = NO;
  98. }
  99. - (NSString *)homeClickedItemName {
  100. if (!_homeClickedItemName) {
  101. _homeClickedItemName = @"";
  102. }
  103. return _homeClickedItemName;
  104. }
  105. - (NSString *)deliveryString {
  106. if (!_deliveryString) {
  107. _deliveryString = @"";
  108. }
  109. return _deliveryString;
  110. }
  111. @end