如何使用警报视图从登录身份验证中注销Google

时间:2019-06-24 11:09:20

标签: ios swift uialertview google-signin

我有一个右栏按钮项(使用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 个答案:

答案 0 :(得分:1)

根据您的描述

@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,因为后者会将旧的vc留在堆栈中