// // ASCurrencyManager.m // Asteria // // Created by iOS on 2023/12/9. // #import "ASCurrencyManager.h" @interface ASCurrencyManager () @end @implementation ASCurrencyManager + (instancetype)shared { static id sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[self alloc] init]; }); return sharedInstance; } - (instancetype)init { self = [super init]; if (self) { self.avaiCurencys = [NSArray array]; } return self; } - (void)setSelectCurrency:(NSString *)sel { [NSUserDefaults.standardUserDefaults setValue:sel forKey:UserLocalCur]; [NSNotificationCenter.defaultCenter postNotificationName:UserLocalCurUpdate object:nil userInfo:@{@"currency":sel}]; } - (NSString *)currentCur { NSString *localCur = [NSUserDefaults.standardUserDefaults stringForKey:UserLocalCur]; if (localCur == nil || localCur.length == 0) { localCur = @"USD"; } return localCur; } - (void)getAllCurrencyData { __weak typeof(self) weakSelf = self; [ASNetTools.shared getWithPath:getAllCurrencyUrl param:@{} success:^(id _Nonnull json) { NSDictionary *dic = (NSDictionary *)json; weakSelf.avaiCurencys = dic[@"available_currency_codes"]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { weakSelf.avaiCurencys = [NSMutableArray array]; }]; } @end