我是swift的新手并尝试使用GPPSignInDelegate实施Google Auth。我得到了登录对话框,但委托方法: - didDisconnectWithError - finishedWithAuth 永远不会被称为。也许我做错了什么。我试图将它翻译得如此迅速而且看起来不错,但有些东西不起作用。有什么建议?感谢您的帮助。
class LoginViewController: UIViewController, GPPSignInDelegate {
var kClientID = "XYZ"
@IBOutlet weak var loginButton: UIButton!
@IBOutlet var gppsloginButton: GPPSignInButton!
var signIn = GPPSignIn.sharedInstance()
override func viewDidLoad() {
super.viewDidLoad()
//var signIn = GPPSignIn.sharedInstance()
signIn.clientID = kClientID;
signIn.scopes = [kGTLAuthScopePlusLogin]
signIn.delegate = self
signIn.authenticate()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func finishedWithAuth(auth: GTMOAuth2Authentication, error: NSError ) -> Void{
debugPrintln("TEST")
}
func didDisconnectWithError ( error: NSError) -> Void{
debugPrintln("TEST2")
}
答案 0 :(得分:1)
我认为您错过了从AppDelegate.swift中的app delegate的URL处理程序添加GPPURLHandler。
此处理程序将正确处理应用程序在身份验证过程结束时收到的URL。
func application(application: UIApplication, openURL url: NSURL, sourceApplication: NSString?, annotation: AnyObject) -> Bool {
return GPPURLHandler.handleURL(url, sourceApplication: sourceApplication, annotation:annotation)
}