ios - 在appDelegate中显示alertView

标签 ios swift uialertview notificationcenter control-center

我试图在通知/控制中心通过 2 个按钮可见之前添加一个 alertView。一个按钮就是“确定”,然后通知/控制中心应该打开。应取消第二个按钮,并且不应显示通知/控制中心。

我尝试在 applicationWillResignActive 中添加 alertView,如下所示:

func applicationWillResignActive(application: UIApplication) {
    var alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
    alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: nil))
    self.presentViewController(alert, animated: true, completion: nil)
}

当用户尝试打开通知/控制中心时,它会稍微打开,然后关闭并显示 alertView。如何在不打开通知/控制中心的情况下显示 alertView

最佳答案

显示您的 AlertView 是因为您的应用程序即将在通知中心显示时退出事件状态,并且您正在从处理此转换的 appDelegate 方法启动它。

你想要实现什么目标?您的应用程序无法阻止通知中心显示,也无法从 AlertView 以编程方式打开它。

您可以查看表2-3中的iOS应用程序状态:

iOS App Lifecycle

关于ios - 在appDelegate中显示alertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32062665/

相关文章:

ios - 将复选框添加到 IOS 6 AlertView

ios - 将 iOS 核心数据添加到现有项目 - 展开可选值时出错

ios - Google Analytics for iOS - 最低部署目标?

ios - UIActivity ActivityViewController 在 Swift 中的 iPad 上崩溃

ios - iPhone 不可用。请重新连接设备。/iOS 14.2 - Xcode 12.1

ios - 在半尺寸父 Controller 中呈现模态视图 Controller

ios - 使用小写字母和数组过滤搜索文本的内容

swift - 结合 map 和 split

objective-c - 防止 UIAlertView 关闭

IOS:如果 UISlider 更改其值,则仅显示一次警报