파이어베이스 -> 콘솔 -> 프로젝트 추가 -> 프로젝트 생성




"""
pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'GoogleSignIn'
pod 'FBSDKLoginKit'
"""
AppDelegate.swift 설정:
import UIKit
import Firebase
import GoogleSignIn
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure() //이거
return true
}
@available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
return GIDSignIn.sharedInstance.handle(url)
}
}
ViewController.swift:
import UIKit
import Firebase
import GoogleSignIn
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance.signIn(with: .init(clientID: FirebaseApp.app()?.options.clientID), presenting: self) { user, error in
if let error = error {
print(error.localizedDescription)
return
}
guard let authentication = user?.authentication, let idToken = authentication.idToken else {
return
}
let credential = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: authentication.accessToken)
Auth.auth().signIn(with: credential) { authResult, error in
if let error = error {
print("Firebase Sign in Error: \\(error)")
return
}
print("User signed in: \\(authResult?.user.email ?? "No email")")
}
}
}
}