Skip to content

Commit 2279e10

Browse files
Create ios_updater_prompt
Signed-off-by: Gilbert Algordo <69397216+gilbertalgordo@users.noreply.github.com>
1 parent 4593751 commit 2279e10

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

ios_updater_prompt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

0 commit comments

Comments
 (0)