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