单击Google登录按钮不显示Safari视图

时间:2017-08-05 07:54:29

标签: ios swift cocoapods firebase-authentication google-signin

我点击谷歌登录按钮,但它没有呈现SafariView,但调用了GIDSignInUIDelegate的委托方法。 除此之外,不会从App Delegate调用GIDSignInDelegate的委托方法。

可能的原因是什么?以下是给出的代码:

我的网址方案:

com.googleusercontent.apps.1028134765971-6ok9n9pemgs3709q70so3bn5u08e84f6

AppDelegate.h

//
//  AppDelegate.swift
//  ESO
//
//  Created by BBI USER 1027 on 23/05/17.
//  Copyright © 2017 BBI. All rights reserved.
//

import UIKit
import Firebase
import GoogleSignIn

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        let signIn = GIDSignIn.sharedInstance()
         signIn?.clientID = FirebaseApp.app()?.options.clientID!
        signIn?.scopes = ["https://www.googleapis.com/auth/plus.login"]
        signIn?.delegate = self
        return true
    }
    func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any])
        -> Bool {
            print(GIDSignIn.sharedInstance().handle(url,
                                                    sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
                                                    annotation: [:]))
            return GIDSignIn.sharedInstance().handle(url,
                                                     sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
                                                     annotation: [:])
    }

    //MARK :  Google sign in delegate methods
    func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
                withError error: NSError!) {
        if (error == nil) {
            // Perform any operations on signed in user here.
            let userId = user.userID                  // For client-side use only!
            let idToken = user.authentication.idToken // Safe to send to the server
            let fullName = user.profile.name
            let givenName = user.profile.givenName
            let familyName = user.profile.familyName
            let email = user.profile.email
            // ...
        } else {
            print("\(error.localizedDescription)")
        }
    }
    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
        // ...
        if let error = error {
            // ...
            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 {
                // ...
                return
            }
            // User is signed in
            // ...
        }

    }
}

FBGoogleSigninViewController.swift

//
//  FBGoogleSigninViewController.swift
//  LoginModule
//
//  Created by Shubham Ojha on 8/4/17.
//  Copyright © 2017 BBI. All rights reserved.
//

import UIKit
import Firebase
import GoogleSignIn

class FBGoogleSigninViewController: UIViewController,GIDSignInUIDelegate {

    @IBOutlet weak var segmentView: UISegmentedControl!
    @IBOutlet weak var loginIDCustomTextField: CustomTextField!
    @IBOutlet weak var passwordCustomTextField: CustomTextField!
    @IBOutlet weak var loginIdLabel: UILabel!
    // On click of this button I am not getting any response.
    @IBOutlet weak var SignInButton: GIDSignInButton!
    override func viewDidLoad() {
        super.viewDidLoad()
        GIDSignIn.sharedInstance().uiDelegate = self;
        GIDSignIn.sharedInstance().signIn()
        self.SignInButton.layer.cornerRadius = 5.0;
        self.navigationController?.setNavigationBarHidden(false, animated: true)
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func segmentValueChanged(_ sender: Any) {
        let segment = sender as! UISegmentedControl
        if segment.selectedSegmentIndex == 0 {
                self.loginIdLabel.text = "Login ID"
            self.SignInButton.backgroundColor = UIColor.blue
        }
        else{
            self.loginIdLabel.text = "Email ID"
            self.SignInButton.backgroundColor = UIColor.red
        }
    }

    // MARK: google sign in delegate methods
    public func sign(inWillDispatch signIn: GIDSignIn!, error: Error!){

    }

    func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!){
        print(viewController.description)
    }


}

0 个答案:

没有答案