Skip to content

Instantly share code, notes, and snippets.

@adriatikgashi
Created May 14, 2020 16:07
Show Gist options
  • Save adriatikgashi/9a54c864d1e5d300b7d8acb744741b9f to your computer and use it in GitHub Desktop.
Save adriatikgashi/9a54c864d1e5d300b7d8acb744741b9f to your computer and use it in GitHub Desktop.
class MainViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
checkForUpdate()
}
private func checkForUpdate() {
ForceUpdateManager.shared.callback = { [unowned self] (appStoreUrl, isRequiredUpdate) -> Void in
DispatchQueue.main.async {
self.showUpdateAlert(appStoreUrl: appStoreUrl, isRequiredUpdate: isRequiredUpdate)
}
}
}
private func showUpdateAlert(appStoreUrl: String, isRequiredUpdate: Bool) {
let title = isRequiredUpdate ? "Required App Update"
: "New Update"
let message = isRequiredUpdate ? "This update contains critical bug fixes, you need to update the app to continue browsing" : "Please, update app to new version!"
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Update", style: .default, handler: { (_) in
if let url = URL(string: appStoreUrl) {
UIApplication.shared.open(url)
}
}))
if !isRequiredUpdate {
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (_) in }))
}
present(alertController, animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment