・firebase の ログイン機能を使ってみる。
・rbenv をインストールして管理する。
・pod がうまくいかない場合は、↓こちらを参照。
1: sudo gem uninstall cocoapods
2: sudo gem install -n /usr/local/bin cocoapods
3: pod install
・
Podfile の中身
pod 'Firebase' pod 'Firebase/Database’ pod 'Firebase/Storage' pod 'Firebase/Auth’ pod 'GoogleSignIn', '~> 5.0'
LoginViewController.swift
import UIKit import GoogleSignIn import Firebase class LoginViewController: UIViewController{ override func viewDidLoad() { super.viewDidLoad() GIDSignIn.sharedInstance().presentingViewController = self GIDSignIn.sharedInstance().delegate = self } @IBAction func signIn(_ sender: Any) { GIDSignIn.sharedInstance().signIn() } @IBAction func signOut(_ sender: AnyObject) { GIDSignIn.sharedInstance().signOut() } } extension LoginViewController: GIDSignInDelegate{ func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { if let error = error { print(error.localizedDescription) return } guard let authentication = user.authentication else { return } let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,accessToken: authentication.accessToken) Auth.auth().signIn(with: credential) { (user, error) in if let error = error { print("Error: \(error.localizedDescription)") return } print(user?.user.uid) print(user?.user.displayName!) } } func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) { // Perform any operations when the user disconnects from app here. // ... }