This commit is contained in:
cheykrym 2025-12-18 07:05:46 +03:00
parent eef02dcca1
commit 216b8f50be

View File

@ -1,4 +1,5 @@
import Foundation
import SwiftUI
import UIKit
struct AppUpdateNotice: Identifiable {
@ -15,27 +16,30 @@ struct AppUpdateNotice: Identifiable {
var title: String {
switch kind {
case .need:
return NSLocalizedString("NeedUpdate.Title", comment: "Need update alert title")
return NSLocalizedString("Обновление обязательно", comment: "Need update alert title")
case .force:
return NSLocalizedString("ForceUpdate.Title", comment: "Force update alert title")
return NSLocalizedString("Рекомендуется обновление", comment: "Force update alert title")
case .soft:
return NSLocalizedString("SoftUpdate.Title", comment: "Soft update alert title")
return NSLocalizedString("Доступно обновление", comment: "Soft update alert title")
}
}
var message: String {
switch kind {
case .need:
return NSLocalizedString("NeedUpdate.Message", comment: "Need update alert message")
return NSLocalizedString("Для продолжения работы необходимо обновить приложение до последней версии.", comment: "Need update alert message")
case .force:
return NSLocalizedString("ForceUpdate.Message", comment: "Force update alert message")
return NSLocalizedString("Эта версия приложения устарела. Некоторые функции могут работать некорректно.", comment: "Force update alert message")
case .soft:
return NSLocalizedString("SoftUpdate.Message", comment: "Soft update alert message")
return NSLocalizedString("Вышла новая версия приложения с улучшениями и исправлениями.", comment: "Soft update alert message")
}
}
}
final class AppUpdateChecker: ObservableObject {
@AppStorage("appIsBlocked") private var isAppBlocked: Bool = false
@AppStorage("lastCheckedAppBuild") private var lastCheckedAppBuild: Int = 0
@Published private(set) var needUpdateNotice: AppUpdateNotice?
@Published private(set) var softUpdateNotice: AppUpdateNotice?
@Published private(set) var forceUpdateNotice: AppUpdateNotice?
@ -108,24 +112,29 @@ final class AppUpdateChecker: ObservableObject {
log("Config missing App Store URL")
return
}
print("buildNumber", buildNumber)
print("config", config.notSupportedBuild, config.minSupportedBuild, config.recommendedBuild)
let requiresNeedUpdate = buildNumber <= config.notSupportedBuild
if requiresNeedUpdate {
isAppBlocked = true
needUpdateNotice = AppUpdateNotice(kind: .need, appStoreURL: appStoreURL)
return
} else {
isAppBlocked = false
}
let requiresForcedUpdate = buildNumber < config.minSupportedBuild
if requiresForcedUpdate {
forceUpdateNotice = AppUpdateNotice(kind: .force, appStoreURL: appStoreURL)
softUpdateNotice = AppUpdateNotice(kind: .force, appStoreURL: appStoreURL)
return
}
if buildNumber < config.recommendedBuild {
if buildNumber < config.recommendedBuild && config.recommendedBuild != lastCheckedAppBuild {
// lastCheckedAppBuild = config.recommendedBuild
softUpdateNotice = AppUpdateNotice(kind: .soft, appStoreURL: appStoreURL)
return
}
}