123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- //
- // LocalManager.swift
- // SwiftBilibili
- //
- // Created by 罗文 on 2021/3/23.
- // Copyright © 2021年 罗文. All rights reserved.
- //
- import UIKit
- import SwiftyUserDefaults
- import RxSwift
- class LocalManager {
-
- static var disposeBag = DisposeBag()
- static let loginService: LoginServiceType = LoginService(networking: LoginNetworking())
- //本地用户信息
- static var userInfo: UserInfo = UserInfo()
- //下载地址
- static var qr_dwanload_url = ""
- //清理
- class func clearUserInfo() {
-
-
- }
-
- //审核account
- static func isCheckAccount()->Bool{
- if LocalManager.userInfo.userAccount == "350211196508204525" {
- return true
- }
- return false
- }
-
- //判断是否登录了
- static func isOpenLogin()->Bool{
- if !LocalManager.userInfo.isLogin {
- NYSwRouter.open(NYSwOpenType.login.rawValue)
- return false
- }
- return true
- }
-
- //自动登录
- static func autoLogin(){
- if LocalManager.userInfo.isLogin {
- let account = LocalManager.userInfo.userAccount!
- let password = LocalManager.userInfo.password!
- let city = LocalManager.userInfo.city!
- LocalManager.loginService.loginRequest(user_name: account, user_password: password,city: city)
- .subscribe(onSuccess: { userinfo in
- NYTips.hide()
- LocalManager.userInfo = userinfo
- }, onError: { error in
- })
- .disposed(by: LocalManager.disposeBag)
- }
-
- }
- //部署信息
- static func getDeploydo(){
- LocalManager.loginService.dictRequest(dictType: "coach_version").subscribe(onSuccess: { cityItems in
- for cityItem in cityItems {
- if cityItem.dictLabel == "ios_version" {
- LocalManager.userInfo.server_version = cityItem.dictValue.replacingOccurrences(of: ".", with: "")
- }else if cityItem.dictLabel == "ios_login_open" {
- LocalManager.userInfo.ios_login_open = Int(cityItem.dictValue)
- }else if cityItem.dictLabel == "qr_app_download" {
- LocalManager.qr_dwanload_url = cityItem.dictValue
- }
- }
- },onError: { Error in
- }).disposed(by: disposeBag)
- }
-
- //验证版本
- static func verifyVersiondo(){
- LocalManager.loginService.dictRequest(dictType: "coach_version").subscribe(onSuccess: { cityItems in
- var server_version = "" //服务端版本
- var message = "有新版本,请到appstore更新" //提示内容
- var isSup = 0 //是否强制更新
- for cityItem in cityItems {
- if cityItem.dictLabel == "ios_version" {
- server_version = cityItem.dictValue.replacingOccurrences(of: ".", with: "")
- let array = cityItem.remark.components(separatedBy: ":")
- if array.count>1 {
- isSup = Int(array[0])!
- message = array[1]
- }
- break
- }
- }
- //当前版本<服务器ios版本提示更新
- let appVersion:String = (NYMacros.appVersion as! String).replacingOccurrences(of: ".", with: "")
- if Int(appVersion)!<Int(server_version)! {
- // https://apps.apple.com/cn/app/%E6%95%99%E7%BB%83%E7%AE%A1%E5%AE%B6/id1214203182
- let action1 = QMUIAlertAction(title: "取消", style: .cancel, handler: nil)
- let action2 = QMUIAlertAction(title: "下载", style: .destructive) { vc, action in
- if let url = URL(string: "itms-apps://itunes.apple.com/cn/app/jiao-li-guan-jia/id1214203182?l=en&mt=8") {
- UIApplication.shared.open(url, options: [:], completionHandler: nil)
- }
- }
- let alertController = QMUIAlertController(title: "提示", message: message, preferredStyle: .alert)
- if isSup == 0 {
- alertController.addAction(action1)
- }
- alertController.addAction(action2)
- let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
- 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
- alertController.mainVisualEffectView = visualEffectView
- alertController.alertHeaderBackgroundColor = nil // Remove these background colors when you need to use the blur effect
- alertController.alertButtonBackgroundColor = nil
- alertController.showWith(animated: true)
-
- }
- },onError: { Error in
- }).disposed(by: disposeBag)
- }
- }
|