ASCurrencyManager.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // ASCurrencyManager.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/12/9.
  6. //
  7. #import "ASCurrencyManager.h"
  8. @interface ASCurrencyManager ()
  9. @end
  10. @implementation ASCurrencyManager
  11. + (instancetype)shared {
  12. static id sharedInstance = nil;
  13. static dispatch_once_t onceToken;
  14. dispatch_once(&onceToken, ^{
  15. sharedInstance = [[self alloc] init];
  16. });
  17. return sharedInstance;
  18. }
  19. - (instancetype)init
  20. {
  21. self = [super init];
  22. if (self) {
  23. self.avaiCurencys = [NSArray array];
  24. }
  25. return self;
  26. }
  27. - (void)setSelectCurrency:(NSString *)sel {
  28. [NSUserDefaults.standardUserDefaults setValue:sel forKey:UserLocalCur];
  29. [NSNotificationCenter.defaultCenter postNotificationName:UserLocalCurUpdate object:nil userInfo:@{@"currency":sel}];
  30. }
  31. - (NSString *)currentCur {
  32. NSString *localCur = [NSUserDefaults.standardUserDefaults stringForKey:UserLocalCur];
  33. if (localCur == nil || localCur.length == 0) {
  34. localCur = @"USD";
  35. }
  36. return localCur;
  37. }
  38. - (void)getAllCurrencyData {
  39. __weak typeof(self) weakSelf = self;
  40. [ASNetTools.shared getWithPath:getAllCurrencyUrl param:@{} success:^(id _Nonnull json) {
  41. NSDictionary *dic = (NSDictionary *)json;
  42. weakSelf.avaiCurencys = dic[@"available_currency_codes"];
  43. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  44. weakSelf.avaiCurencys = [NSMutableArray array];
  45. }];
  46. }
  47. @end