Supports updating apps from AppViewController

Unlike MyAppsViewController, AppViewController will attempt to update to the latest available version, rather than the latest supported version. If the latest version is not supported, it will fall back to asking user to install last supported version.
This commit is contained in:
Riley Testut
2022-11-16 18:02:38 -06:00
parent 1444afa2b5
commit 60b7276ac4

View File

@@ -371,13 +371,20 @@ private extension AppViewController
button.tintColor = self.app.tintColor
button.isIndicatingActivity = false
if self.app.installedApp == nil
if let installedApp = self.app.installedApp
{
button.setTitle(NSLocalizedString("FREE", comment: ""), for: .normal)
if let latestVersion = self.app.latestAvailableVersion, installedApp.version != latestVersion.version
{
button.setTitle(NSLocalizedString("UPDATE", comment: ""), for: .normal)
}
else
{
button.setTitle(NSLocalizedString("OPEN", comment: ""), for: .normal)
}
}
else
{
button.setTitle(NSLocalizedString("OPEN", comment: ""), for: .normal)
button.setTitle(NSLocalizedString("FREE", comment: ""), for: .normal)
}
let progress = AppManager.shared.installationProgress(for: self.app)
@@ -486,7 +493,14 @@ extension AppViewController
{
if let installedApp = self.app.installedApp
{
self.open(installedApp)
if let latestVersion = self.app.latestAvailableVersion, installedApp.version != latestVersion.version
{
self.updateApp(installedApp)
}
else
{
self.open(installedApp)
}
}
else
{
@@ -531,6 +545,34 @@ extension AppViewController
{
UIApplication.shared.open(installedApp.openAppURL)
}
func updateApp(_ installedApp: InstalledApp)
{
let previousProgress = AppManager.shared.installationProgress(for: installedApp)
guard previousProgress == nil else {
//TODO: Handle cancellation
//previousProgress?.cancel()
return
}
_ = AppManager.shared.update(installedApp, to: .latestAvailableVersionWithFallback, presentingViewController: self) { (result) in
DispatchQueue.main.async {
switch result
{
case .success: print("Updated app from AppViewController:", installedApp.bundleIdentifier)
case .failure(OperationError.cancelled): break
case .failure(let error):
let toastView = ToastView(error: error)
toastView.opensErrorLog = true
toastView.show(in: self)
}
self.update()
}
}
self.update()
}
}
private extension AppViewController