'Prevent UIAlertController from dismissing on UIAlertAction
I am working on one of the application where i am promoting user for force update using UIAlertController
in which i don't wanted to allow user to perform any activity until and unless he updates the application from AppStore.
To achieve this i have written following code.
if (needToUpdate)
{
var alert = UIAlertController(title: "New Version Available", message: "There is a newer version available for download! Please update the app by visiting the Apple Store.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(
UIAlertAction(
title: "Update",
style: UIAlertActionStyle.Default,
handler: { alertAction in
UIApplication.sharedApplication().openURL(NSURL(string : "https://itunes.apple.com/app/cheapo-casino-free-casino/id637522371?ls=1&mt=8")!)
alert.dismissViewControllerAnimated(true, completion: nil)
}
)
)
self.presentViewController(alert, animated: true, completion: nil)
}
It is working good but whenever user presses Update button it will go to app store and if user don't update the application. he/she will come back to application and can perform any activity which is not expected.
Is there any way to show the UIAlertController
even if user press update button?
Solution 1:[1]
You can check the version of the app in appDelegate.
func applicationDidBecomeActive(_ application: UIApplication) {
//check the app version here and if version mismatch is there show the alert.
// if the version is different then make initial viewController as root view controller. and then present alert from that view controller.
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |