LNConfigManager.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // LNConfigManager.swift
  3. // Lanu
  4. //
  5. // Created by OneeChan on 2025/12/25.
  6. //
  7. import Foundation
  8. enum LNBannerAdSlot: Int {
  9. case homeAd = 1
  10. case roomAd = 2
  11. case walletAd = 3
  12. }
  13. class LNConfigManager {
  14. static let shared = LNConfigManager()
  15. private(set) var commonConfig = LNConfigResponse()
  16. var isBeanAvailable: Bool {
  17. guard let version = commonConfig.appReviewSpecialVersionConfig?.ios else { return false }
  18. if version.isEmpty { return true }
  19. guard let iVersion = Int(version) else { return false }
  20. if iVersion == 0 { return true }
  21. guard let curVersion = Int(curBuildVersion) else { return false }
  22. return curVersion < iVersion
  23. }
  24. private init() {
  25. LNEventDeliver.addObserver(self)
  26. }
  27. func reloadCommonConfig() {
  28. LNHttpManager.shared.getCommonConfig { [weak self] res, err in
  29. guard let self else { return }
  30. guard let res else { return }
  31. commonConfig = res
  32. }
  33. }
  34. func getCountryCodeList(queue: DispatchQueue = .main, handler: @escaping ([LNCountryCodeVO]?) -> Void) {
  35. LNHttpManager.shared.getCountryCodeList { res, err in
  36. queue.asyncIfNotGlobal {
  37. handler(res?.list)
  38. }
  39. if let err {
  40. showToast(err.errorDesc)
  41. }
  42. }
  43. }
  44. func getBannerList(adSlot: LNBannerAdSlot, queue: DispatchQueue = .main, handler: @escaping ([LNBannerInfoVO]?) -> Void) {
  45. LNHttpManager.shared.getBannerList(adSlot: adSlot.rawValue) { res, err in
  46. queue.asyncIfNotGlobal {
  47. handler(res?.list)
  48. }
  49. }
  50. }
  51. func getUpdateInfo(queue: DispatchQueue = .main, handler: @escaping (LNForceUpdateConfigResponse?) -> Void) {
  52. LNHttpManager.shared.getUpdateInfo { res, err in
  53. queue.asyncIfNotGlobal {
  54. handler(res)
  55. }
  56. }
  57. }
  58. }
  59. extension LNConfigManager: LNAccountManagerNotify {
  60. func onUserLogin() {
  61. reloadCommonConfig()
  62. }
  63. }