Arti Arti - 1 month ago 10
Swift Question

Google sign in not redirect to application after allow

I'm using this tutorial to implement Sign in with google in app.


  1. I installed GoogleSignIn via cocoapods.
    pod 'GoogleSignIn', '~> 2.4.0'

  2. Added
    GSignIn-Bridging-Header.h
    with
    #import <GoogleSignIn/GoogleSignIn.h>
    inside.

  3. Create url types: enter image description here

  4. Create a view with
    GIDSignInButton
    class

  5. Added code:

    class ViewController: UIViewController, GIDSignInDelegate, GIDSignInUIDelegate {
    override func viewDidLoad() {
    super.viewDidLoad()
    GIDSignIn.sharedInstance().delegate = self
    GIDSignIn.sharedInstance().uiDelegate = self
    GIDSignIn.sharedInstance().clientID = "KEY"
    }

    func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
    if let err = error {
    print(error)
    }
    else {
    print(GIDSignIn.sharedInstance().currentUser.profile.name)
    print(GIDSignIn.sharedInstance().currentUser.profile.email)
    self.performSegueWithIdentifier("idSegueContent", sender: self)
    }
    }


    func signIn(signIn: GIDSignIn!, didDisconnectWithUser user: GIDGoogleUser!, withError error: NSError!) {

    }
    }

  6. But when i click allow



enter image description here

It redirects me to google.com, not to app.

Answer

In the AppDelegate, You need to add the Implementation of

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
{
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}

Google sends back information through URL, the method above captures this information and send back to the Application.

Comments