gpt4 book ai didi

ios - 关闭所有当前呈现的 UIAlertControllers

转载 作者:搜寻专家 更新时间:2023-10-31 21:51:58 25 4
gpt4 key购买 nike

有没有办法关闭当前显示的所有 UIAlertController?

这是因为在我的应用程序的任何地方和任何状态下,我都需要在按下推送通知时到达某个 ViewController。

最佳答案

func dismissAnyAlertControllerIfPresent() {
guard let window :UIWindow = UIApplication.shared.keyWindow , var topVC = window.rootViewController?.presentedViewController else {return}
while topVC.presentedViewController != nil {
topVC = topVC.presentedViewController!
}
if topVC.isKind(of: UIAlertController.self) {
topVC.dismiss(animated: false, completion: nil)
}
}

这对我有用!

编辑:适用于 iOS 13+

 func dismissAnyAlertControllerIfPresent() {
guard let window = windows.first(where: { $0.isKeyWindow }),
var topVC = window.rootViewController?.presentedViewController else {return}
while topVC.presentedViewController != nil {
topVC = topVC.presentedViewController!
}
if topVC.isKind(of: UIAlertController.self) {
topVC.dismiss(animated: false, completion: nil)
}
}

关于ios - 关闭所有当前呈现的 UIAlertControllers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28636640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com