Как выйти из Google с помощью Авторизации при входе в систему, используя представление предупреждений - PullRequest
1 голос
/ 24 июня 2019

У меня есть элемент кнопки правой панели (с использованием SWReveal Controller), и я хочу выйти из системы, используя вид предупреждений, показывающий всплывающие окна «ОК» и «Отмена», если я нажимаю «ОК», это должно означать печать и переходить кна странице, и если я нажимаю «Отмена», она должна оставаться такой же .......

Я получаю ошибки

здесь мой код:

 @IBAction func logoutButton(_ sender: Any) {
    let alert = UIAlertController(title: "Alert", message: "Are you Sure You want to Logout", preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
        switch action.style{
        case .default:
            print("Please Enter Details")

        case .cancel:
            print("cancel")

        case .destructive:
            print("destructive")
        }}))
    self.present(alert, animated: true, completion: nil)
    GIDSignIn.sharedInstance().delegate = self
    GIDSignIn.sharedInstance().uiDelegate = self
    GIDSignIn.sharedInstance().signOut()
    let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "signinpage") as! ViewController
    self.navigationController?.pushViewController(secondViewController, animated: true)

    alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: { action in
        switch action.style{
        case .default:
            print("Please Enter Details")
        case .cancel:
            print("cancel")

        case .destructive:
            print("destructive")
        }}))
    self.present(alert, animated: true, completion: nil)
     let secondViewController2 = self.storyboard?.instantiateViewController(withIdentifier: "HomeViewController")  as! HomeViewController
     self.navigationController?.pushViewController(secondViewController2,  animated: true)

}

1 Ответ

1 голос
/ 24 июня 2019

Согласно вашему описанию вам нужно

@IBAction func logoutButton(_ sender: Any) {

    let alert = UIAlertController(title: "Alert", message: "Are you Sure You want to Logout", preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
        GIDSignIn.sharedInstance().signOut()
        let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "signinpage") as! ViewController
        self.navigationController?.setViewControllers([secondViewController], animated: true)
    }))
    alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler:nil))
    self.present(alert, animated: true, completion: nil)

}

При выходе из системы лучше использовать setViewControllers вместо popViewController, так как последний оставит старые vcs в стеке

...