1
This commit is contained in:
parent
f903e4cfae
commit
d8fd08c58c
@ -166,6 +166,7 @@ extension FAPayRetainAlert {
|
||||
}
|
||||
|
||||
private static let defaultCountdownSeconds = 4 * 60 * 60
|
||||
private static let countdownEndTimeKey = "FAPayRetainCountdownEndTime"
|
||||
private var countdownTimer: Timer?
|
||||
private var remainingSeconds: Int = 0
|
||||
|
||||
@ -252,8 +253,12 @@ extension FAPayRetainAlert {
|
||||
// 每次展示时从 4 小时开始倒计时
|
||||
private func startCountdown() {
|
||||
stopCountdown()
|
||||
remainingSeconds = Self.defaultCountdownSeconds
|
||||
let endTime = resolveEndTime()
|
||||
remainingSeconds = max(0, Int(endTime - Date().timeIntervalSince1970))
|
||||
updateTimeLabels()
|
||||
guard remainingSeconds > 0 else {
|
||||
return
|
||||
}
|
||||
countdownTimer = Timer.scheduledTimer(timeInterval: 1,
|
||||
target: YYTextWeakProxy(target: self),
|
||||
selector: #selector(handleCountdownTimer),
|
||||
@ -276,6 +281,18 @@ extension FAPayRetainAlert {
|
||||
updateTimeLabels()
|
||||
}
|
||||
|
||||
private func resolveEndTime() -> TimeInterval {
|
||||
let defaults = UserDefaults.standard
|
||||
let now = Date().timeIntervalSince1970
|
||||
let storedEndTime = defaults.double(forKey: Self.countdownEndTimeKey)
|
||||
if storedEndTime > now {
|
||||
return storedEndTime
|
||||
}
|
||||
let newEndTime = now + TimeInterval(Self.defaultCountdownSeconds)
|
||||
defaults.set(newEndTime, forKey: Self.countdownEndTimeKey)
|
||||
return newEndTime
|
||||
}
|
||||
|
||||
private func updateTimeLabels() {
|
||||
let hours = remainingSeconds / 3600
|
||||
let minutes = (remainingSeconds % 3600) / 60
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user