LocalManager.swift 4.7 KB

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