jsdw_ios/QuickLocation/Section/Home/SignIn/SignInVC.swift

70 lines
2.1 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.

//
// SignInVC.swift
// QuickLocation
//
// Created by on 2026/6/17.
//
import UIKit
import RxSwift
import RxCocoa
import CoreLocation
class SignInVC: BaseViewController {
fileprivate var rootView: SignInView!
override func loadView() {
rootView = SignInView(frame: UIScreen.main.bounds)
view = rootView
}
///
var lastLocation: CLLocation?
private let geocoder = CLGeocoder()
private var isSignIn: Bool = false
override func viewDidLoad() {
super.viewDidLoad()
requestSignInInfo()
rootView.signInLottieView.rx.tapGesture.subscribe(onNext: { [weak self] _ in
self?.dl.showLoading()
guard let self = self, let loc = self.lastLocation, isSignIn == false else { return }
self.geocoder.reverseGeocodeLocation(loc) { [weak self] placemarks, error in
self?.dl.dismiss()
guard let self = self else { return }
let address = placemarks?.first?.name
?? placemarks?.first?.thoroughfare
?? placemarks?.first?.locality
?? ""
MQTTService.shared.reportSignIn(lat: loc.coordinate.latitude, lon: loc.coordinate.longitude, addr: address)
self.dl.show(text: "签到成功") {
self.requestSignInInfo()
}
}
}).disposed(by: disposeBag)
}
// MARK: - API
private func requestSignInInfo() {
DLToast.showLoading()
UserService.signInInfo().subscribe(onNext: { response in
guard let model = response.model else { return }
self.isSignIn = model.signInStatus == 1
self.rootView.setupData(model)
}, onError: { _ in }).disposed(by: disposeBag)
}
init(lastLocation: CLLocation?) {
self.lastLocation = lastLocation
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}