【问题标题】:Prevent UIAlertController from dismissing on UIAlertAction防止 UIAlertController 在 UIAlertAction 上解除
【发布时间】: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


【解决方案1】:

您可以在 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.
}

【讨论】:

    猜你喜欢
    • 2014-10-26
    • 1970-01-01
    • 1970-01-01
    • 2016-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 2014-12-08
    相关资源
    最近更新 更多