ios - 防止 UIAlertController 在 UIAlertAction 上关闭

标签 ios swift uialertcontroller uialertaction

我正在开发一个应用程序,我正在使用 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/

相关文章:

swift - 无法实例化使用另一个泛型作为参数的泛型类型 - 无法为类型调用初始值设定项

ios - 调用中的额外参数 'mobileNumber'

Swift:在 viewDidLoad() 和回调中运行单例函数,不会得到相同的结果

ios - 使用未解析的标识符 'displayAlertMessage'

ios - 使用 Apple Push Notifications (APN) for Passbook 时 token 无效

ios - 火力地堡崩溃。 xcode 9.没有谷歌服务

ios - Xcode 7 Beta 5,UITableViewCells subview 被裁剪出 ContentView

swift - 为什么我的 UIPickerview 无法在 UIAlertcontroller 中工作?

swift - 如何在 UIAlertController 中添加 UIPickerView?

ios - 从 AVPlayerViewController 中删除 QuickTime 图标