// // CountDownManager.swift // QuickSearchLocation // // Created by Destiny on 2025/9/24. // import UIKit class QSLCountdownManager { static let shared = QSLCountdownManager() private var timer: Timer? var selectGood: QSLGoodModel? var remainingSeconds: Int = 900 // 15分钟 = 900秒 var updateHandler: ((String) -> Void)? var updateHandler1: ((String) -> Void)? var finishHandler: (() -> Void)? func startCountdown() { timer?.invalidate() timer = nil if(selectGood == nil){ return } remainingSeconds = 900 timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateCountdown), userInfo: nil, repeats: true) RunLoop.current.add(timer!, forMode: .common) } func stopCountdown() { finishHandler?() timer?.invalidate() timer = nil } @objc private func updateCountdown() { remainingSeconds -= 1 if remainingSeconds <= 0 { stopCountdown() } let hours = remainingSeconds / 3600 let minutes = (remainingSeconds % 3600) / 60 let seconds = remainingSeconds % 60 let timeString = String(format: "%02d : %02d : %02d", hours, minutes, seconds) updateHandler?(timeString) updateHandler1?(timeString) } deinit { stopCountdown() } }