我正在开发一个应用程序,我正在使用 UIAlertController
促进用户强制更新,其中我不想允许用户执行任何事件,直到并且除非他从应用商店。
为了实现这一点,我编写了以下代码。
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)
}
它运行良好,但每当用户按下“更新”按钮时,它都会转到应用程序商店,并且如果用户不更新应用程序。他/她将返回应用程序并可以执行任何意外的事件。
即使用户按下更新按钮,是否有办法显示UIAlertController
?
最佳答案
您可以在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.
}
关于ios - 防止 UIAlertController 在 UIAlertAction 上关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47777461/