Swift Firebase Google Login Tutorial

preview_player
Показать описание
How to login to Firebase in Google with Swift.

Рекомендации по теме
Комментарии
Автор

Very helpful! This finally got it working for me. The Google documentation only makes sense after you see someone do it first.

MrCNBPS
Автор

That's really helpful, even after watching lot of tutorial it was not clear to me how to use firebase for sign in. Can you explain how to navigate on new view controller after signing in successfully.

anujchoubey
Автор

I don't know why this is implemented completely in AppDelegate. If you want to transition to another View Controller which would be the use-case 99% of the time then the delegate methods need to be implemented IN the presenting View Controller i.e. where you have the "Sign-in with Google Account" button.

To accomplish this place the following code in the viewDidLoad method in the View Controller:
= self
= self
= "your client ID as indicated in the video"

make sure you have imported the following in the View Controller file:
import GoogleSignIn
import FirebaseAuth

In the your button target @objc function (in case it's a custom button which would also be the case 90% of the time) just add this one line:
// This will trigger the delegate functions

And the delegate functions will go in the View Controller
extension YourViewController : GIDSignInDelegate {
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!)
// fill this function in as indicated in the video
// if there is no error then transition to the desired View Controller

func application(_ app: UIApplication, open url: URL, options: : Any] = [:]) -> Bool { return }

Don't forget these functions in the delegate method as well:
func sign(_ signIn: GIDSignIn?, present viewController: UIViewController?) {

if let dialogController = viewController {
present(aController, animated: true) {() -> Void in }
}
}

func sign(_ signIn: GIDSignIn?, dismiss viewController: UIViewController?) {

dismiss(animated: true) {() -> Void in }
}

slasht
Автор

Fantastic! How can I add transition to next page after signed in with google? In app delegate doesn’t work, please help

leonardosperati