谷歌登陆后的冥想

时间:2017-10-02 19:16:23

标签: ios swift segue google-signin google-login

google登录后我无法让我的segue工作。首先,我正在使用SwiftKeychainWrapper来存储用户信息。我已经将它用于Facebook并且它可以工作但是,现在我正在设置Google LogIn,它会中断。我已经尝试了几种不同的方法:将委托放入appDelegate但是,这不允许segue,将委托放入登录VC,它只是不移动。

有人可以帮忙!!!!

import UIKit
import Firebase
import SwiftKeychainWrapper
import FBSDKCoreKit
import FBSDKLoginKit
import GoogleSignIn

class SignIn: UIViewController, GIDSignInUIDelegate, GIDSignInDelegate, UITextFieldDelegate {



    @IBOutlet weak var emailField: UITextField!
    @IBOutlet weak var passwordField: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.emailField.delegate = self
        self.passwordField.delegate = self

        GIDSignIn.sharedInstance().uiDelegate = self
        GIDSignIn.sharedInstance().signInSilently()
        GIDSignIn.sharedInstance().clientID = FirebaseApp.app()!.options.clientID
        GIDSignIn.sharedInstance().delegate = self

        }

    override func viewDidAppear(_ animated: Bool) {
        if let _ = KeychainWrapper.standard.string(forKey: KEY_UID){
            print("NOTE: ID found in keychain")
            performSegue(withIdentifier: "goToFeed", sender: nil)
        }
    }

    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        if (GIDSignIn.sharedInstance().hasAuthInKeychain()){
            print("signed in")
            performSegue(withIdentifier: "goToFeed", sender: self)
        }
    }

        func googleBtnTapped(_ sender: Any) {

        if let authentication = user.authentication
        {
            let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)

            Auth.auth()?.signIn(with: credential, completion: { (user, error) -> Void in
                if error != nil
                {
                    print("Problem at signing in with google with error : \(error)")

                }
                else if error == nil{
                    print("user successfully signed in through GOOGLE! uid:\(FIRAuth.auth()!.currentUser!.uid)")

                }
            })
        }
    }
    

    @IBAction func facebookBtnTapped(_ sender: AnyObject) {

        let facebookLogin = FBSDKLoginManager()

        facebookLogin.logIn(withReadPermissions: ["email"], from: self) { (result, error) in
            if error != nil {
                print("NOTE: Unable to authenticate with Facebook - \(String(describing: error))")
            } else if result?.isCancelled == true {
                print("NOTE: User cancelled Facebook authentication")
            } else {
                print("NOTE: Successfully authenticated with Facebook")
                let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)
                self.firebaseAuth(credential)
            }
        }

    }

我现在已经好几天了,现在我正在寻找各种帮助。感谢。

2 个答案:

答案 0 :(得分:2)

只需在 for aa = 1:length(Ytotal) if Ytotal(aa) > ymean+yerrorstd; Ytotal(aa)=[]; x(aa)=[]; else Ytotal(aa)=Ytotal(aa); x(aa)=x(aa); end end 函数中调用GIDSignIn.sharedInstance().signIn(),如下所示:

googleBtnTapped

然后将身份验证代码放在func googleBtnTapped(_ sender: Any) { GIDSignIn.sharedInstance().signIn() } 函数中,如下所示:

sign

答案 1 :(得分:0)

我还要在上述解决方案中添加。不要忘记在GIDSignIn.sharedInstance().delegate = self中添加viewController,否则将无法正常工作。