impression7vx impression7vx - 4 months ago 34
iOS Question

Google Sign In Button does Nothing

I have implemented the Google Sign In exactly as Google states to according to their website. I had it working about a month ago, now it just does nothing. I tried to redo everything by deleting the cocoapod and following their website to a T but nothing is happening still. It is like none of the delegate methods are being called, and I am unsure why. Any help would be appreciative. Thanks!

import GoogleSignIn
import Google
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

//Get Twitter and set Twitter keys for Application
Twitter.sharedInstance().startWithConsumerKey("uBedaxDuMDgImGbjun1oYf0ay", consumerSecret: "OaKqBZUesX5CypHCwrTvTZE22jrXIuRsUeZzVaMHej11R5Vh3b")
Fabric.with([Twitter.self])

// Initialize sign-in GOOGLE
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")

GIDSignIn.sharedInstance().delegate = self

return true
}

func application(application: UIApplication,
openURL url: NSURL, options: [String: AnyObject]) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String,
annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}

func application(application: UIApplication,
openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
var options: [String: AnyObject] = [UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication!,
UIApplicationOpenURLOptionsAnnotationKey: annotation!]
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: sourceApplication,
annotation: annotation)
}

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
print("SIGNING IN")
if (error == nil) {
let email = user.profile.email
print(user.authentication)
// ...
} else {
print("ERROR = \(error.localizedDescription)")
}
}


View Controller

import GoogleSignIn
class LoginViewController: UIViewController, UITextFieldDelegate, CLLocationManagerDelegate, GIDSignInUIDelegate
override func viewDidLoad() {

//Default setup for View Controller
super.viewDidLoad()

GIDSignIn.sharedInstance().uiDelegate = self
var error:NSError?
GGLContext.sharedInstance().configureWithError(&error)
if(error != nil) {
print(error)
}

var signInButton = GIDSignInButton(frame: CGRect(x: 0, y: 0, width: 150, height: 400))
view.addSubview(signInButton)

}


EDIT

After HOURS, lol, of figuring this out, the Google Sign-In Button works when it is
1)Held down for more than 2 seconds,
2)Swiped left/down/right but not up
I am unsure of this cause and would be open to suggestions! Thanks!

Answer

I have figured it out, would like to let anyone else know this stupid stupid issue!

The problem is with the Google button and the tap I have to dismiss the keyboard. I didn't put it on here, but here it is.

let tap = UITapGestureRecognizer(target: self, action: #selector(LoginViewController.dismissKeyboard))
self.view.addGestureRecognizer(tap)

func dismissKeyboard() {
    self.view.endEditing(true)
}

Google's Delegates mess this up for some reason. I haven't come up with a solution yet, as I literally just now found the issue, but if anyone else has an issue, I hope this helps!

Comments