WepsTech
Your Daily Dose of Tech News
Hello Guys, Welcome to the new tutorial. Here I am going to tell you how to do Google login in iOS with firebase. Google developer tools provide lot’s of features but today in this tutorial we are going to cove only Google login with firebase.
The very first step is.You have to create on project into Firebase. As shown into the video. So please first follow the procedures from firebase developer website.
After that, enable Google authentication in firebase. As mention into video.
After that, If you done with all the setup then import GoogleSignIn as mention below in AppDelegate.swift
import GoogleSignIn
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. FirebaseApp.configure() GIDSignIn.sharedInstance()?.clientID = FirebaseApp.app()?.options.clientID return true } // MARK: UISceneSession Lifecycle func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { return (GIDSignIn.sharedInstance()?.handle(url))! } }
Great, In Above file we have add one function which is open url: URL function. And we have edit didFinishLaunchingWithOptions function.
Now go to your loginController File and import the package in your file as mentioned below!
import GoogleSignIn
@IBOutlet weak var lb_login_Status: UILabel! @IBOutlet weak var btn_sign_out: UIButton! override func viewDidLoad() { super.viewDidLoad() self.btn_sign_out.isHidden = true GIDSignIn.sharedInstance()?.delegate = self currentUserName() }
func currentUserName() { if let currentUser = Auth.auth().currentUser { self.btn_sign_out.isHidden = false lb_login_Status.text = "YOU ARE LOGIN AS - " + (currentUser.displayName ?? "DISPLAY NAME NOT FOUND") } }
This function will help you for getting current user name!
After that, You do not need to anything. I hope you understand this tutorial very well. If you have any question in your mind so please comment below. In conclusion if you still did not understand then please watch the following video. After watching this video it will be clear to you, That how to do Google Login in iOS
If you are looking few more tutorial then go through with below links.