如何让Google登录按钮在Xcode 9.3中运行?

时间:2018-01-27 23:23:12

标签: swift4 gidsignin

我无法在Xcode 9.3-beta中使用google登录按钮。

以下是我的app delegate中的代码:

import UIKit
import Firebase
import GoogleSignIn

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        //Initialize Firebase
        FirebaseApp.configure()
        GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
        GIDSignIn.sharedInstance().delegate = self
        // Override point for customization after application launch.
        return true
    }


    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
        // ...
        if error != nil {
            // ...
            return
        }
        guard let authentication = user.authentication else { return }
        let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
        // ...
    }
    @available(iOS 9.3, *)
    func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any])
        -> Bool {
            return GIDSignIn.sharedInstance().handle(url, sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: [:])
    }
}

这是我的注册视图控制器的代码:

import UIKit
import Firebase
import GoogleSignIn

class registerViewController: UIViewController, GIDSignInUIDelegate {

    @IBOutlet weak var emailTextField: UITextField!
    @IBOutlet weak var passwordTextField: UITextField!
    @IBOutlet weak var signInButton: GIDSignInButton!

    //Email_password combination
    @IBAction func complete(_ sender: Any) {
    Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!) {
            (user, error) in

            if error != nil {
                    print(error!)
            } else {
                //success
                let welcomeMessage = "Signed In"
                let alert = UIAlertController(title: welcomeMessage, message: "Welcome", preferredStyle: .alert)
                alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .`default`, handler: { _ in
                    NSLog("The \"OK\" alert occured.")
                }))
                self.present(alert, animated: true, completion: nil)
            }
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        GIDSignIn.sharedInstance().uiDelegate = self
        GIDSignIn.sharedInstance().signIn()

        // Do any additional setup after loading the view.
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    //GID sign in method
    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
        // ...
        if error != nil {
            // ...
            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 error != nil {
                // ...
                return
            }
            // User is signed in
            // ...
        }
        // ...
    }

当我运行此应用程序时,我可以成功导航到我的注册视图控制器,并且我的GID登录按钮的视图已成功加载。但是,单击按钮时没有任何反应。我已经使用了几个小时并且没有得到任何地方。

在调试控制台中,不会出现错误。但我确实在顶部:

  

“Interface Builder文件中的未知类_TtC4LEAF14ViewController。”

我也得到了

  

“状态栏找不到缓存的时间字符串图像。正在进行渲染。”

我无法弄清楚其中任何一个是指什么。我确保使用正确的URL类型,并正确合并了pod文件。我的电子邮件密码组合也可以。

1 个答案:

答案 0 :(得分:0)

我遇到了与Xcode 9.3(正式版)和Google登录类似的问题。我使用Xcode 9.4 beta进行了测试,一切都再次运行。