prompt to update on ios

This commit is contained in:
ivan grachev 2023-10-29 18:05:29 +03:00
parent 1527d1fe8c
commit 15072c119f
4 changed files with 29 additions and 1 deletions

View File

@ -9,5 +9,6 @@ extension URL {
static let email = URL(string: "mailto:support@tokenary.io")!
static let iosSafariGuide = URL(string: "https://tokenary.io/guide-ios")!
static let appStore = URL(string: "https://tokenary.io/get")!
static let updateApp = URL(string: "https://lil.org/update")!
}

View File

@ -4,7 +4,12 @@ import Foundation
class ConfigurationService {
var shouldUpdateApp = Defaults.didReceiveShouldUpdateAppNotification
var shouldPromptToUpdate: Bool {
return shouldUpdateApp && !didPropmtToUpdate
}
private var shouldUpdateApp = Defaults.didReceiveShouldUpdateAppNotification
private var didPropmtToUpdate = false
private struct ConfigurationResponse: Codable {
let shouldUpdateApp: Bool
@ -22,6 +27,10 @@ class ConfigurationService {
}
}
func didPromptToUpdate() {
didPropmtToUpdate = true
}
private func getConfiguration() {
let url = URL(string: "https://tokenary.io/t-app-configuration")!
let dataTask = urlSession.dataTask(with: url) { [weak self] (data, _, _) in

View File

@ -93,5 +93,8 @@ struct Strings {
static let switchAccountTwoLines = "Switch\nAccount"
static let unknownNetwork = "Unknown network ⚠️"
static let addAccountToConnect = "Add %@ account to connect"
static let thisAppVersionIsNoLongerSupported = "this app version is no longer supported 🥺"
static let pleaseGetANewOne = "please get a new one"
static let notNow = "not now"
}

View File

@ -133,6 +133,7 @@ class AccountsListViewController: UIViewController, DataStateContainer {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
processInput()
requestAnUpdateIfNeeded()
didAppear = true
DispatchQueue.main.async { [weak self] in
let heightBefore = self?.navigationController?.navigationBar.frame.height ?? 0
@ -147,6 +148,20 @@ class AccountsListViewController: UIViewController, DataStateContainer {
}
}
private func requestAnUpdateIfNeeded() {
let configurationService = ConfigurationService.shared
guard !didAppear, configurationService.shouldPromptToUpdate else { return }
configurationService.didPromptToUpdate()
let alert = UIAlertController(title: Strings.thisAppVersionIsNoLongerSupported, message: Strings.pleaseGetANewOne, preferredStyle: .alert)
let notNowAction = UIAlertAction(title: Strings.notNow, style: .destructive)
let okAction = UIAlertAction(title: Strings.ok, style: .default) { _ in
UIApplication.shared.open(URL.updateApp)
}
alert.addAction(notNowAction)
alert.addAction(okAction)
present(alert, animated: true)
}
private func scrollToTheFirst(_ specificWalletAccounts: Set<SpecificWalletAccount>) {
for (sectionIndex, section) in sections.enumerated() {
for (row, cellModel) in section.items.enumerated() {