ios - 使用 UIAlertController 退出应用程序

标签 ios swift uialertcontroller uicontrol

如果用户在没有互联网连接的情况下打开应用程序,则会弹出一个窗口,提示需要连接,并有一个确定按钮。我想要确定按钮退出应用程序。这是我所拥有的:

if !isConnectedToNetwork(){
    let alert = UIAlertController(title: "No Internet", message: "You need an internet connection to use this app", preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
    self.presentViewController(alert, animated: true, completion: nil)
}

我将使用它来退出应用程序:

UIControl().sendAction(Selector("suspend"), to: UIApplication.sharedApplication(), forEvent: nil)

我只是不知道如何将它连接到上面的 OK 按钮。

最佳答案

不要。苹果会拒绝这个(如果他们看到的话)。

只需通知用户并添加“重试”按钮即可。重试按钮显然应该再次检查连接。

要真正回答这个问题,您目前已经在按钮操作上设置了 handler: nil,您实际上可以设置一个处理程序并使用它来调用您喜欢的任何逻辑。

关于ios - 使用 UIAlertController 退出应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36406256/

相关文章:

ios - 无法使用CoreData配置RestKit

ios - 在不设置密码的情况下确定 iOS 设备是否支持 TouchID

ios - 使用 textViewDidChange 限制 UITextView 中的字符

ios - 更改标签栏的背景颜色

ios - 在 shouldPerformSegueWithIdentifier UIAlertController 之后未执行 Unwind Segue

ios - Swift UIAlertController 文件重命名操作

ios - 在 XCode 上为 iOS 使用自定义构建的 OpenCV 会产生 ___sincos_stret undefined symbol

ios - Game Center 可以与非游戏 iOS 应用程序集成吗

ios - 在 UITableView 单元格中加载 UITableView 的最佳方法是什么?

ios - 在所有 View Controller 中创建警报功能 - swift