Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

Firebase Google Login doesn't work / Swift

I integrated everything like in the tutorial on YouTube but it doesn't work. When I tap on the Button it does nothing... I imported all modules and installed all pods. Can someone help me? Link to the tutorial: https://www.youtube.com/watch?v=20Qlho0G3YQ

ViewController

let googleLoginButton = GIDSignInButton()

override func viewDidLoad() {
        super.viewDidLoad()
        
        GIDSignIn.sharedInstance()?.presentingViewController = self
        
        ...

}

func configureStackView() {
        loginView.addSubview(StackView)
        StackView.alignment = .center
        StackView.distribution = .equalSpacing
        StackView.axis = .horizontal
        StackView.backgroundColor = .white
        StackView.spacing = 5
        
        //Adding Elements
        StackView.addArrangedSubview(googleLoginButton)
        StackView.addArrangedSubview(facebookLoginButton)
        StackView.addArrangedSubview(appleLoginButton)
        
        
        //Constraints
        StackView.translatesAutoresizingMaskIntoConstraints = false
        StackView.centerXAnchor.constraint(equalTo: loginView.centerXAnchor).isActive = true
        StackView.bottomAnchor.constraint(equalTo: loginView.bottomAnchor, constant: -10).isActive = true
        StackView.heightAnchor.constraint(equalToConstant: 100).isActive = true
        StackView.leadingAnchor.constraint(equalTo: loginView.leadingAnchor, constant: 35).isActive = true
        StackView.trailingAnchor.constraint(equalTo: loginView.trailingAnchor, constant: -35).isActive = true
    
        //MARK: - Configure Login Buttons
        
    //Configure GoogleButton
//        googleLoginButton.setImage(googleLogo, for: .normal)
        googleLoginButton.layer.cornerRadius = 25
//        googleLoginButton.imageView?.contentMode = .scaleAspectFit
       
        
        //Constraints
        googleLoginButton.translatesAutoresizingMaskIntoConstraints = false
        googleLoginButton.widthAnchor.constraint(equalToConstant: 45).isActive = true
        googleLoginButton.heightAnchor.constraint(equalToConstant: 45).isActive = true

   
...

App Delegate

import UIKit
import CoreData
import Firebase
import GoogleSignIn

@main
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
       
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.makeKeyAndVisible()
        
        
        
        let mainController = LoginVCViewController()
        window?.rootViewController = mainController
        
        FirebaseApp.configure()
        GIDSignIn.sharedInstance()?.clientID = "7029977741-p82g70k9kfqqkljp08edb4q5jilp4le3.apps.googleusercontent.com"
        GIDSignIn.sharedInstance()?.delegate = self
        return true
    }
    
    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        print("User: (user.profile.email ?? "No Email")")
    }
    
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        return ((GIDSignIn.sharedInstance()?.handle(url)) != nil)
    }

Thanks in advance

Second Question: How can I customize the Button that only the G is visible and its round?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...