我应该如何发出在 swift 后超时的警报

How should I issue an alert that times out in swift

我正在使用 UIAlertController 来显示需要用户操作的用户警报。我想跳过用户操作并在一段时间后(比如 10 秒)让警报消失。最好的方法是什么?

在创建 UIAlertViewController 后试试这个

var dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(10.0 * Double(NSEC_PER_SEC))) 
dispatch_after(dispatchTime, dispatch_get_main_queue(), { 
    yourAlertViewController.dismissViewControllerAnimated(true, completion: nil)   
})

这非常适合您

    //Define & Initialize Alert (Example)
    var alert: UIAlertController = UIAlertController();      

    // Delay the execution (Dismiss AlertController) by 10 seconds
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        alert.dismissViewControllerAnimated(true, completion: nil)
    });