| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- //
- // Singleton.m
- // iSales-NPD
- //
- // Created by Jack on 2016/10/12.
- // Copyright © 2016年 United Software Applications, Inc. All rights reserved.
- //
- #import "RASingleton.h"
- #import "NotificationNameCenter.h"
- #import "AppDelegate.h"
- #import "RAUtils.h"
- @interface RASingleton ()
- @property (nonatomic,strong) NSMutableDictionary *globalParameters;
- @end
- @implementation RASingleton
- #pragma mark - Global Parameter
- - (NSMutableDictionary *)globalParameters {
- if (!_globalParameters) {
- _globalParameters = [NSMutableDictionary dictionary];
- }
- return _globalParameters;
- }
- - (void)setGlobalParameter:(id)param forKey:(NSString *)key {
- if (param == nil || key == nil) {
- return;
- }
- [self.globalParameters setObject:param forKey:key];
- }
- - (id)globalParameterForKey:(NSString *)key {
- if (key == nil) {
- return nil;
- }
- return [self.globalParameters objectForKey:key];
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
-
- [self removeObserver:self forKeyPath:@"stack_contents"];
- }
- //- (instancetype)init {
- // if (self = [super init]) {
- //
- // [self addObserver:self forKeyPath:@"scan_cart"
- // options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
- // context:@"content changed"];
- //
- // }
- // return self;
- //}
- + (instancetype)sharedInstance {
-
- static RASingleton *singleton = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
-
- singleton = [[RASingleton alloc] init];
- [[NSNotificationCenter defaultCenter] addObserver:singleton selector:@selector(handleLogin:) name:User_LoginOK_Notification object:nil];
-
-
- // self addObserver:self forKeyPath:self.scan_cart options:<#(NSKeyValueObservingOptions)#> context:<#(nullable void *)#>
- });
- return singleton;
- }
- //- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
- //{
- // if(self.enable_OfflineOrder)
- // {
- // if([keyPath isEqualToString:@"scan_cart"])
- // {
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //
- //
- // NSString *orderdir = [documents stringByAppendingPathComponent:appDelegate.order_code];
- //
- // NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
- //
- //
- //
- // [RAUtils dicttofile:cartpath dict:self.scan_cart];
- //
- //
- // self.scan_cart addObserver:<#(nonnull NSObject *)#> forKeyPath:<#(nonnull NSString *)#> options:<#(NSKeyValueObservingOptions)#> context:<#(nullable void *)#>
- //
- // }
- // }
- //
- //}
- - (void)setGlobal_lock:(BOOL)global_lock {
- _global_lock = global_lock;
- if (global_lock) {
- [[NSNotificationCenter defaultCenter] postNotificationName:Lock_Permission_Notification object:nil];
- } else {
- [[NSNotificationCenter defaultCenter] postNotificationName:unLock_Permission_Notification object:nil];
- }
- }
- - (void)resetGlobalLock {
- _global_lock = NO;
- }
- - (void)handleLogin:(NSNotification *)notification {
- self.currentOrderIsMerged = NO;
- }
- - (NSString *)homeClickedItemName {
- if (!_homeClickedItemName) {
- _homeClickedItemName = @"";
- }
- return _homeClickedItemName;
- }
- - (NSString *)deliveryString {
- if (!_deliveryString) {
- _deliveryString = @"";
- }
- return _deliveryString;
- }
- @end
|