我已经完全按照 Google 根据其网站声明的方式实现了 Google 登录。我大约一个月前让它工作,现在它什么都不做。我试图通过删除 cocoapod 并关注他们的网站到 T 来重做所有事情,但仍然没有任何反应。好像没有调用任何委托(delegate)方法,我不确定为什么。任何帮助将不胜感激。谢谢!
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)
}
编辑
HOURS 之后,大声笑,弄清楚了这一点后,Google 登录按钮就可以正常工作了 1)按住2秒以上, 2)向左/向下/向右滑动但不向上滑动 我不确定这个原因,愿意接受建议!谢谢!
最佳答案
我遇到了同样的问题,这是绑定(bind)到主视图以关闭键盘的点击手势识别器的问题。它不小心也捕获了 GIDSignInButton 内部的触摸。更改此设置有帮助:
tapGesture.cancelsTouchesInView = false
关于ios - Google 登录按钮什么都不做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37741890/