File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ import UIKit
2+
3+ class ViewController: UIViewController {
4+ let updateManager = UpdateManager()
5+
6+ override func viewDidAppear(_ animated: Bool) {
7+ super.viewDidAppear(animated)
8+ checkForUpdates()
9+ }
10+
11+ private func checkForUpdates() {
12+ updateManager.checkForUpdate { [weak self] isUpdateAvailable, releaseNotes, downloadURL in
13+ guard let self = self, isUpdateAvailable, let downloadURL = downloadURL else { return }
14+
15+ DispatchQueue.main.async {
16+ self.showUpdateAlert(releaseNotes: releaseNotes, updateURL: downloadURL)
17+ }
18+ }
19+ }
20+
21+ private func showUpdateAlert(releaseNotes: String?, updateURL: String) {
22+ let alert = UIAlertController(title: "Update Available",
23+ message: releaseNotes ?? "A new version is available.",
24+ preferredStyle: .alert)
25+
26+ alert.addAction(UIAlertAction(title: "Update", style: .default, handler: { _ in
27+ if let url = URL(string: updateURL) {
28+ UIApplication.shared.open(url)
29+ }
30+ }))
31+
32+ alert.addAction(UIAlertAction(title: "Later", style: .cancel, handler: nil))
33+
34+ present(alert, animated: true)
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments