LocalManager.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // LocalManager.swift
  3. // SwiftBilibili
  4. //
  5. // Created by 罗文 on 2021/3/23.
  6. // Copyright © 2021年 罗文. All rights reserved.
  7. //
  8. import UIKit
  9. import SwiftyUserDefaults
  10. import RxSwift
  11. class LocalManager {
  12. static var disposeBag = DisposeBag()
  13. static let loginService: LoginServiceType = LoginService(networking: LoginNetworking())
  14. //本地用户信息
  15. static var userInfo: UserInfo = UserInfo()
  16. //下载地址
  17. static var qr_dwanload_url = ""
  18. //清理
  19. class func clearUserInfo() {
  20. }
  21. //审核account
  22. static func isCheckAccount()->Bool{
  23. if LocalManager.userInfo.userAccount == "350211196508204525" {
  24. return true
  25. }
  26. return false
  27. }
  28. //判断是否登录了
  29. static func isOpenLogin()->Bool{
  30. if !LocalManager.userInfo.isLogin {
  31. NYSwRouter.open(NYSwOpenType.login.rawValue)
  32. return false
  33. }
  34. return true
  35. }
  36. //自动登录
  37. static func autoLogin(){
  38. if LocalManager.userInfo.isLogin {
  39. let account = LocalManager.userInfo.userAccount!
  40. let password = LocalManager.userInfo.password!
  41. let city = LocalManager.userInfo.city!
  42. LocalManager.loginService.loginRequest(user_name: account, user_password: password,city: city)
  43. .subscribe(onSuccess: { userinfo in
  44. NYTips.hide()
  45. LocalManager.userInfo = userinfo
  46. }, onError: { error in
  47. })
  48. .disposed(by: LocalManager.disposeBag)
  49. }
  50. }
  51. //部署信息
  52. static func getDeploydo(){
  53. LocalManager.loginService.dictRequest(dictType: "coach_version").subscribe(onSuccess: { cityItems in
  54. for cityItem in cityItems {
  55. if cityItem.dictLabel == "ios_version" {
  56. LocalManager.userInfo.server_version = cityItem.dictValue.replacingOccurrences(of: ".", with: "")
  57. }else if cityItem.dictLabel == "ios_login_open" {
  58. LocalManager.userInfo.ios_login_open = Int(cityItem.dictValue)
  59. }else if cityItem.dictLabel == "qr_app_download" {
  60. LocalManager.qr_dwanload_url = cityItem.dictValue
  61. }
  62. }
  63. },onError: { Error in
  64. }).disposed(by: disposeBag)
  65. }
  66. //验证版本
  67. static func verifyVersiondo(){
  68. LocalManager.loginService.dictRequest(dictType: "coach_version").subscribe(onSuccess: { cityItems in
  69. var server_version = "" //服务端版本
  70. var message = "有新版本,请到appstore更新" //提示内容
  71. var isSup = 0 //是否强制更新
  72. for cityItem in cityItems {
  73. if cityItem.dictLabel == "ios_version" {
  74. server_version = cityItem.dictValue.replacingOccurrences(of: ".", with: "")
  75. let array = cityItem.remark.components(separatedBy: ":")
  76. if array.count>1 {
  77. isSup = Int(array[0])!
  78. message = array[1]
  79. }
  80. break
  81. }
  82. }
  83. //当前版本<服务器ios版本提示更新
  84. let appVersion:String = (NYMacros.appVersion as! String).replacingOccurrences(of: ".", with: "")
  85. if Int(appVersion)!<Int(server_version)! {
  86. // https://apps.apple.com/cn/app/%E6%95%99%E7%BB%83%E7%AE%A1%E5%AE%B6/id1214203182
  87. let action1 = QMUIAlertAction(title: "取消", style: .cancel, handler: nil)
  88. let action2 = QMUIAlertAction(title: "下载", style: .destructive) { vc, action in
  89. if let url = URL(string: "itms-apps://itunes.apple.com/cn/app/jiao-li-guan-jia/id1214203182?l=en&mt=8") {
  90. UIApplication.shared.open(url, options: [:], completionHandler: nil)
  91. }
  92. }
  93. let alertController = QMUIAlertController(title: "提示", message: message, preferredStyle: .alert)
  94. if isSup == 0 {
  95. alertController.addAction(action1)
  96. }
  97. alertController.addAction(action2)
  98. let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
  99. visualEffectView.qmui_foregroundColor = UIColor(255, 255, 255,0.7) // UIColorMakeWithRGBA(255, 255, 255, 0.7) // Use the default value in most cases, only demonstrate how to set here
  100. alertController.mainVisualEffectView = visualEffectView
  101. alertController.alertHeaderBackgroundColor = nil // Remove these background colors when you need to use the blur effect
  102. alertController.alertButtonBackgroundColor = nil
  103. alertController.showWith(animated: true)
  104. }
  105. },onError: { Error in
  106. }).disposed(by: disposeBag)
  107. }
  108. }