Every UIAlertController disappear automatically before user responds - since iOS 13

后端 未结 3 1417
孤城傲影
孤城傲影 2020-12-09 13:01

Since I\'m using iOS 13, each of my UIAlertController shows up for about half a second and disappears instantly before any user action. Any idea ?

As I use

3条回答
  •  无人及你
    2020-12-09 13:23

    You can try this solution also. It is working form me.

    write below method in your class.

    func presentViewController(alertController: UIAlertController, completion: (() -> Void)? = nil) {
            if var topController = UIApplication.shared.keyWindow?.rootViewController {
                while let presentedViewController = topController.presentedViewController {
                    topController = presentedViewController
                }
    
                DispatchQueue.main.async {
                    topController.present(alertController, animated: true, completion: completion)
                }
            }
        }
    

    Then call it from your code as below

    let alertController = UIAlertController(title: "Discard Photo?",
                                                    message: "Your photo will not be attached",
                                                    preferredStyle: .alert)
            alertController.addAction(UIAlertAction(title: "Keep Photo", style: .default, handler: nil))
            alertController.addAction(UIAlertAction(title: "Discard", style: .default) { (_) -> Void in
                self.PhotoStack.deletePhoto(at: index)
                self.cameraBtn.isEnabled = true
            })
    
            self.presentViewController(alertController: alertController)
    

提交回复
热议问题