ios - 如何使用警报 View 从登录身份验证中退出 Google

标签 ios swift uialertview google-signin

我有一个右栏按钮项(使用 SWReveal Controller ),我想使用显示“确定”的警报 View 注销,如果我单击“确定”弹出“取消”,它应该是 signet 并且必须导航到签名-在页面中,如果我点击“取消”,它应该保持不变......

我遇到了错误

这里是我的代码:

 @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)

}

最佳答案

根据你的描述你需要

@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

关于ios - 如何使用警报 View 从登录身份验证中退出 Google,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56735296/

相关文章:

ios - TestFlight 是否支持 ios7 及更早版本?

ios - 在 iPad 中显示矢量 map

ios - PHAsset:什么是 'assetSource' ?

iOS - 未调用警报 View 的 segue

iphone - 有没有非私有(private) API 替代方案?

ios - UIScrollView 中的 drawRect 方法

ios - 延迟后自动切换uiview

ios - 如果用户未登录,则将用户从 TabBar 重定向到登录 viewController (Swift)

swift - 如何更改 NSButton 的位置?

objective-c - UIAlertView 添加 NSString