【发布时间】:2018-05-26 10:10:59
【问题描述】:
我正在开发一个应用程序,我正在使用 UIAlertController 促进用户进行强制更新,在该应用程序中我不想允许用户执行任何活动,除非他从 Appstore 更新应用程序。
为了实现这一点,我编写了以下代码。
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?
【问题讨论】:
-
仅供参考 - Apple 真的不希望应用程序做你正在做的事情。让用户决定是否要更新。就我个人而言,我讨厌那些在我不想更新时强迫我更新的应用。
-
虽然我基本同意上面的评论,但我不得不问:如果你不希望它关闭,你为什么打电话给
dismissViewControllerAnimated? -
这个链接可能对你有帮助stackoverflow.com/questions/28919670/…
-
@PhillipMills 对
dismissViewController的调用毫无意义,甚至不应该存在。一旦点击按钮,您就无法阻止警报控制器被关闭。它会自动关闭。
标签: swift uialertcontroller uialertaction