Open new swift 4 screen

1

I have a webview app, after the lauchScreen it goes to the ViewController where it loads the page, I have a class that does the check if there is a connection, and if it does not exist I would like to open a new screen warning that it is offline or show a button of a reload in the app, in order to try to open again and if there is connection the app open normally.

Follow 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    
       }
   }
}
    
asked by anonymous 18.07.2018 / 03:04

1 answer

1

You can create an 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)

   //Criação dos botões de ação 
   let reload = UIAlertAction(title: "Recarregar", style: .default) { (action:UIAlertAction) in
       //Ação ao pressionar recarregar
   }

   let cancel = UIAlertAction(title: "Cancelar", style: .default) { (action:UIAlertAction) in
       //Ação ao pressionar cancelar
   }    

   //Adicionando os botões no alerta
   alertController.addAction(reload)
   alertController.addAction(cancel)

   //Mostrando ele na tela
   self.present(alertController, animated: true, completion: nil)
}
    
31.07.2018 / 19:45