Вот мой код для этого в iOS 13:
AppDelegate.swift
import Firebase
import GoogleSignIn
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
// configure de firebase app
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
return true
}
// other methods in app delegate
@available(iOS 9.0, *)
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
return GIDSignIn.sharedInstance().handle(url)
}
}
SceneDelegate.swift
import Firebase
import GoogleSignIn
import FirebaseAuth
// conform to the google sign in delegate
class SceneDelegate: UIResponder, UIWindowSceneDelegate, GIDSignInDelegate {
var window: UIWindow?
// when the app launches, it checks if the user is signed in, and redirect to the correct view controller
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let windowScene = scene as? UIWindowScene {
self.window = UIWindow(windowScene: windowScene)
if Auth.auth().currentUser != nil {
// redirect to the home controller
self.window!.rootViewController = storyboard.instantiateViewController(withIdentifier: "HomeTabBarController")
self.window!.makeKeyAndVisible()
} else {
// redirect to the login controller
self.window!.rootViewController = storyboard.instantiateViewController(withIdentifier: "LoginViewController")
self.window!.makeKeyAndVisible()
}
}
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
}
// handle the sign in to redirect to the home controller
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
if error != nil {
return
}
guard let authentication = user.authentication else { return }
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
Auth.auth().signIn(with: credential) { (authResult, error) in
if let error = error {
print(error.localizedDescription)
return
}
let storyboard = UIStoryboard(name: "Main", bundle: nil)
// redirect the user to the home controller
self.window!.rootViewController = storyboard.instantiateViewController(withIdentifier: "HomeTabBarController")
self.window!.makeKeyAndVisible()
}
}
func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
// Perform any operations when the user disconnects from app here.
// ...
}
}