Open new screen Swift 4

Asked

Viewed 164 times

1

I have a webview app, after the lauchScreen it goes to the Viewcontroller where it loads the page, I have a class that checks if there is a connection, and if there is not I would like to open a new screen warning that it is not connected or show a button that of a Reload in the app, in order to try to open again and if there is connection the app open normally.

Follows the code:

class ViewController: UIViewController {

   @IBOutlet weak var WebView: WKWebView!

   override func viewDidLoad() {
       super.viewDidLoad()

       if(CheckInternet.Connection()){

           let url = URL(string: "https://google.com")
           let request = URLRequest(url:url!)
           WebView.load(request)

       }else{
          //caso n tenha conexão com a internet    
       }
   }
}

1 answer

1

You can create a alertController, it is a simple warning where you can configure the actions of each button, when the action you want to happen is just call this function:

func createAllert(){
    //Criação do alerta
    let alertController = UIAlertController(title: "Titulo do Alerta", message: "mensagem do alerta", preferredStyle: .alert)

//Creation of action buttons Let Reload = Uialertaction(title: "Reload", style: .default) { (action:Uialertaction) in //Action when pressing reload } Let Cancel = Uialertaction(title: "Cancel", style: .default) { (action:Uialertaction) in //Action when pressing cancel } //Adding buttons to the alert alertController.addAction(Reload) alertController.addAction(Cancel) //Showing it on screen self.present(alertController, Animated: true, Completion: nil) }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.