Google SignIn Delegate Navigation to second viewController SWIFT 4
I have some problem in login google, i want to google login auto to next layout, no back to firstViewController but next viewController ( secondViewcontroller )
Google button --> Sign In -->First Controller
Google button --> Sign In --> Second View Controller
and finally i solve problem like this code below.
1. func sign
Google button --> Sign In -->
and finally i solve problem like this code below.
1. func sign
import UIKit import GoogleSignInclass LoginViewController: UIViewController, GIDSignInUIDelegate, GIDSignInDelegate{
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { if GIDSignIn.sharedInstance().hasAuthInKeychain() { // Signed in let vc = secondViewController() self.navigationController?.setViewControllers([vc], animated: true) } else { self.dismiss(animated: true, completion: nil) }
.....
2. in ViewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().signInSilently()
TextFiled()
//if the user is already logged in
if (FBSDKAccessToken.current()) != nil{
getFBUserData()
}
}
Full LoginViewController.swift
import UIKit
import GoogleSignIn
class LoginViewController: UIViewController, GIDSignInUIDelegate, GIDSignInDelegate{
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if GIDSignIn.sharedInstance().hasAuthInKeychain() {
// Signed in
let vc = secondViewController()
self.navigationController?.setViewControllers([vc], animated: true)
} else {
self.dismiss(animated: true, completion: nil)
}
}
var user = GIDSignIn()
@IBAction func gButton(_ sender: Any) {
GIDSignIn.sharedInstance().signIn()
}
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().signInSilently()
}
}
This my note as my problem and solution @luffyselah
No comments: