Files
suixinkan_uikit/suixinkan/DataStore/AppLocationStore.swift
汉秋 c083f1d4b3 升级 AppStore 缓存 Key 并在覆盖安装时强制重新登录。
统一账号作用域 Key 对齐 Android,新增缓存 schema 迁移清理旧数据,并同步更新相关模块与单元测试。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-14 09:35:55 +08:00

78 lines
2.3 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.

//
// AppLocationStore.swift
// suixinkan
//
import Foundation
///
final class AppLocationStore {
private enum Key: String, CaseIterable {
case onlineStatus = "key_online_status"
case lastReportTime = "key_last_location_report_time"
case reminderMinutes = "key_location_reminder_minutes"
}
private let defaults: UserDefaults
private let session: AppSessionStore
/// 使
init(defaults: UserDefaults, session: AppSessionStore) {
self.defaults = defaults
self.session = session
}
/// 线
var onlineStatus: Bool {
get {
guard let key = scopedKey(.onlineStatus) else { return false }
return defaults.bool(forKey: key)
}
set {
guard let key = scopedKey(.onlineStatus) else { return }
defaults.set(newValue, forKey: key)
}
}
///
var lastReportTime: Int64 {
get {
guard let key = scopedKey(.lastReportTime) else { return 0 }
return Int64(defaults.integer(forKey: key))
}
set {
guard let key = scopedKey(.lastReportTime) else { return }
defaults.set(Int(newValue), forKey: key)
}
}
/// 0
var reminderMinutes: Int {
get {
guard let key = scopedKey(.reminderMinutes) else { return 0 }
return defaults.integer(forKey: key)
}
set {
guard let key = scopedKey(.reminderMinutes) else { return }
defaults.set(newValue, forKey: key)
}
}
///
func clearLastReportTime() {
guard let key = scopedKey(.lastReportTime) else { return }
defaults.removeObject(forKey: key)
}
///
func clear(accountScope: String) {
guard !accountScope.isEmpty else { return }
Key.allCases.forEach { defaults.removeObject(forKey: "\(accountScope)_\($0.rawValue)") }
}
private func scopedKey(_ key: Key) -> String? {
session.accountScopedKey(key.rawValue)
}
}