jsdw_ios/QuickLocation/Section/Mine/About/AboutVC.swift

128 lines
4.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AboutVC.swift
// QuickLocation
//
import UIKit
import RxSwift
import RxCocoa
final class AboutVC: BaseViewController {
private var rootView: AboutView!
private var logoTapCount = 0
private var logoTapResetWork: DispatchWorkItem?
override func loadView() {
rootView = AboutView(frame: UIScreen.main.bounds)
view = rootView
}
override func viewDidLoad() {
super.viewDidLoad()
bind()
}
private func bind() {
rootView.navView.onBackTapped = { [weak self] in
self?.navigationController?.popViewController(animated: true)
}
let logoTap = UITapGestureRecognizer(target: self, action: #selector(handleLogoTap))
rootView.logoImage.addGestureRecognizer(logoTap)
rootView.feedbackBtn.rx.controlEvent(.touchUpInside)
.subscribe(onNext: { _ in
AppRouter.push(Route.feedback)
})
.disposed(by: disposeBag)
rootView.rateBtn.rx.controlEvent(.touchUpInside)
.subscribe(onNext: { _ in
Self.openAppStoreReview()
})
.disposed(by: disposeBag)
rootView.agreementBtn.rx.controlEvent(.touchUpInside)
.subscribe(onNext: { _ in
AppRouter.push(Route.web, userInfo: ["url": URLManager.shared.userAgreementUrl])
})
.disposed(by: disposeBag)
rootView.privacyBtn.rx.controlEvent(.touchUpInside)
.subscribe(onNext: { _ in
AppRouter.push(Route.web, userInfo: ["url": URLManager.shared.privacyPolicyUrl])
})
.disposed(by: disposeBag)
rootView.kidsPrivacyBtn.rx.controlEvent(.touchUpInside)
.subscribe(onNext: { _ in
AppRouter.push(Route.web, userInfo: ["url": URLManager.shared.kidsPrivacyUrl])
})
.disposed(by: disposeBag)
}
@objc private func handleLogoTap() {
logoTapResetWork?.cancel()
logoTapCount += 1
if logoTapCount >= 5 {
logoTapCount = 0
showServerSwitchAlert()
return
}
let work = DispatchWorkItem { [weak self] in
self?.logoTapCount = 0
}
logoTapResetWork = work
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: work)
}
private func showServerSwitchAlert() {
let current = URLManager.shared.apiServerURL
let alert = UIAlertController(
title: "切换接口",
message: "当前:\(current)",
preferredStyle: .alert
)
alert.addTextField { field in
field.placeholder = "自定义接口地址"
field.text = current
field.keyboardType = .URL
field.autocorrectionType = .no
field.autocapitalizationType = .none
}
for preset in URLManager.presetServers {
alert.addAction(UIAlertAction(title: preset.title, style: .default) { [weak self] _ in
self?.applyServer(url: preset.url, env: preset.env)
})
}
alert.addAction(UIAlertAction(title: "确定", style: .default) { [weak self] _ in
let typed = alert.textFields?.first?.text ?? ""
self?.applyServer(url: typed, env: nil)
})
alert.addAction(UIAlertAction(title: "取消", style: .cancel))
present(alert, animated: true)
}
private func applyServer(url: String, env: Int?) {
let normalized = URLManager.normalizedServerURL(url)
guard !normalized.isEmpty else {
DLToast.show(text: "请输入接口地址")
return
}
URLManager.shared.switchServer(url: normalized, env: env)
AppDelegate.shared.showMainViewController()
}
private static func openAppStoreReview() {
// Bundle appId
let appId = AppSettings.shared.appId
guard !appId.isEmpty,
let url = URL(string: "itms-apps://itunes.apple.com/app/id\(appId)?action=write-review") else {
DLToast.show(text: "暂无法打开评价")
return
}
UIApplication.shared.open(url)
}
}